Python - 使用virtualenv手动安装包

时间:2022-11-21 00:24:13

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?

我有一个python程序,我想安装到我的virtualenv - 这是一个拉链包,我需要解压缩,然后运行一个setup.py程序 - 但我的问题更多关于如何将这些解压缩的文件放入我的virtualenv所以包安装到virtualenv的site-packages文件夹中?

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.

我也可以使用pip install 从我的virtualenv内部安装,但由于某种原因,PIP下载的包已过期。

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:

到目前为止,我已经有了加载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?

那么 - 解压缩python包/程序的位置是否重要 - 或者我应该在解压缩之前首先登录virtualenv?在我加载了virtualenv并且我在内部使用'workon test'命令之后,我安装的任何python包,无论我找到它的目录,都将自己安装到正确的virtualenv的site-packages文件夹中?

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.

选项1是将python程序解压缩到/ home / username / tmp - 然后登录到我的virtualenv,导航到该文件夹​​并运行setup.py程序 - 假设virtualenv将所有相关文件传输到它自己的site-packages文件夹。

OR scenario 2 is to unzip the files directly into site-packages, and run it from there (after logging in to the virtualenv), etc

或者方案2是将文件直接解压缩到站点包中,然后从那里运行(登录到virtualenv后)等等

Thank you for helping a Python clutz with this!

感谢您帮助Python clutz!

2 个解决方案

#1


101  

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)

我通常会将程序解压缩到一个临时文件夹,然后从该文件夹运行setup.py,使用virtualenv python实例的直接路径。例如,如果你的virtualenv在/ home / username / virtualpy中,请使用它(来自你的临时文件夹)

/home/username/virtualpy/bin/python setup.py install

This should install it to your virtualenv site package folder.

这应该将它安装到您的virtualenv站点包文件夹中。

#2


9  

well when you switch to the virtual environment. you should type

当你切换到虚拟环境时。你应该打字

which python

哪个python

and if it returns the path where your virtual environment exists then its okay you can directly run this command.

如果它返回您的虚拟环境存在的路径,那么可以直接运行此命令。

$ python setup.py build
$ python setup.py install

but if it gives the global level path which is not your virtualenv's path then you should try using

但如果它给出了不是你的virtualenv路径的全局级别路径,那么你应该尝试使用

$ ~/.virtualenv/python-env/bin/python setup.py build
$ ~/.virtualenv/python-env/bin/python setup.py install

#1


101  

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)

我通常会将程序解压缩到一个临时文件夹,然后从该文件夹运行setup.py,使用virtualenv python实例的直接路径。例如,如果你的virtualenv在/ home / username / virtualpy中,请使用它(来自你的临时文件夹)

/home/username/virtualpy/bin/python setup.py install

This should install it to your virtualenv site package folder.

这应该将它安装到您的virtualenv站点包文件夹中。

#2


9  

well when you switch to the virtual environment. you should type

当你切换到虚拟环境时。你应该打字

which python

哪个python

and if it returns the path where your virtual environment exists then its okay you can directly run this command.

如果它返回您的虚拟环境存在的路径,那么可以直接运行此命令。

$ python setup.py build
$ python setup.py install

but if it gives the global level path which is not your virtualenv's path then you should try using

但如果它给出了不是你的virtualenv路径的全局级别路径,那么你应该尝试使用

$ ~/.virtualenv/python-env/bin/python setup.py build
$ ~/.virtualenv/python-env/bin/python setup.py install