Python - 使用 virtualenv 手动安装包
我有一个 python 程序,我想安装到我的 virtualenv 中 - 这是一个 zip 包,我需要解压然后运行 setup.py 程序 - 但我的问题更多是关于如何将这些解压缩的文件放入我的 virtualenv 中,以便该包安装到 virtualenv 的 site-packages 文件夹中?
我还可以使用 pip install
从 virtualenv 内部安装,但由于某种原因,PIP 下载的包已过期。
那么 - 有人可以告诉我手动安装软件包的一些简单步骤吗?
到目前为止,我已经有了加载 Virtualenv 的基本命令:
-bash-3.2$ source ~/.bashrc
-bash-3.2$ workon test
(test)-bash-3.2$ //Now I'm working on my virtualenv, but where do I go after this??
那么 - 我将 python 包/程序解压到哪里有关系吗 - 或者我应该在解压之前先登录到 virtualenv ?加载 virtualenv 并在内部使用“workon test”命令使用它后,无论我找到它的目录如何,我安装的任何 python 包都会将其自身安装到正确的 virtualenv 的 site-packages 文件夹中吗?
选项 1 是将 python 程序解压到 /home/username/tmp - 然后登录到我的 virtualenv,导航到该文件夹并运行 setup.py 程序 - 假设 virtualenv 会将所有相关文件传输到它自己的 site-packages 文件夹。
或者方案 2 是将文件直接解压缩到站点包中,并从那里运行它(登录到 virtualenv 后),等等
感谢您帮助 Python 笨蛋解决这个问题!
I have a python program I want to install into my virtualenv - it's a zip package that I need to unzip and then run a setup.py program - but my question is more regarding how to get these unzipped files into my virtualenv so that the package gets installed into the virtualenv's site-packages folder?
I can also install from inside my virtualenv using pip install <package name>
, but for some reason, the package that PIP downloads is out of date.
So - can someone tell me a few easy steps for installing a package manually?
So far I have the basic commands to load up the Virtualenv:
-bash-3.2$ source ~/.bashrc
-bash-3.2$ workon test
(test)-bash-3.2$ //Now I'm working on my virtualenv, but where do I go after this??
So - does it matter where I unzip the python package/program to - or should I be logged in to the virtualenv first before unzipping? After I load up the virtualenv and I'm inside using it with the 'workon test' command, will any python package I install, regardless of the directory I find it, install itself into the proper virtualenv's site-packages folder?
Option 1 is to unzip the python program into /home/username/tmp - then log into my virtualenv, navigate to that folder and run the setup.py program - assuming that the virtualenv will transfer all relevant files to it's own site-packages folder.
OR scenario 2 is to unzip the files directly into site-packages, and run it from there (after logging in to the virtualenv), etc
Thank you for helping a Python clutz with this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通常会将程序提取到一个临时文件夹,然后从该文件夹中使用 virtualenv python 实例的直接路径运行 setup.py。例如,如果您的 virtualenv 位于 /home/username/virtualpy 中,请使用它(从您的临时文件夹)
这应该将其安装到您的 virtualenv 站点包文件夹中。
I typically would extract the program to a temporary folder, then from that folder, run the setup.py using the direct path to the virtualenv python instance. eg if your virtualenv is in /home/username/virtualpy, use this (from your temporary folder)
This should install it to your virtualenv site package folder.
当你切换到虚拟环境时就好了。你应该输入
which python
,如果它返回你的虚拟环境所在的路径,那么你可以直接运行这个命令。
但如果它给出的全局级别路径不是您的 virtualenv 路径,那么您应该尝试使用
well when you switch to the virtual environment. you should type
which python
and if it returns the path where your virtual environment exists then its okay you can directly run this command.
but if it gives the global level path which is not your
virtualenv's
path then you should try using如果无法从存储库安装软件包,请尝试使用 sudo 在 venv 下安装。
作为 python pathos 包的示例;
If a package won't install from repository, try under venv by use sudo.
As example for python pathos package;
PACKAGE_DIR=/some/package/目录/路径
导出 VENV=$(pipenv --venv) &&导出 BASE_DIR=$(pwd) && cd $PACKAGE_DIR && $VENV/bin/python setup.py install && cd $BASE_DIR
PACKAGE_DIR=/some/package/directory/path
export VENV=$(pipenv --venv) && export BASE_DIR=$(pwd) && cd $PACKAGE_DIR && $VENV/bin/python setup.py install && cd $BASE_DIR