pip 将 python 包安装到默认安装位置以外的特定目录中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17216689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pip install python package into a specific directory other than the default install location
提问by user2502020
The default location where pip installes packages on my Ubuntu system is '/usr/local/lib/pytho2.7/dist-packages/' which I think is the default in general. I am using Enthought python distribution (EPD not canopy) and would like to install a package into EPD as I usually work with the python from the EPD distribution on my system. I would like to know into which directory inside EPD the new files need to be installed using pip ; as the directory structure for EPD on linux seems to be quite different from the EPD directory structure on MAC OS for where there seem to be many examples.
pip 在我的 Ubuntu 系统上安装软件包的默认位置是“/usr/local/lib/pytho2.7/dist-packages/”,我认为这通常是默认位置。我正在使用 Enthought python 发行版(EPD 不是 canopy)并且想将一个包安装到 EPD 中,因为我通常在我的系统上使用来自 EPD 发行版的 python。我想知道需要使用 pip 将新文件安装到 EPD 中的哪个目录中;因为 linux 上的 EPD 目录结构似乎与 MAC OS 上的 EPD 目录结构大不相同,因为那里似乎有很多例子。
Also I have come across this :
我也遇到过这个:
pip install --install-option="--prefix=$PREFIX_PATH" package_name
as the accepted answer to a question similar to this. I would like to know what the purpose of the $PREFIX_PATH environment variable is as mine is currently blank. And what path I need to specify on Ubuntu for my Enthought EPD distribution to install python modules.
作为与此类似的问题的公认答案。我想知道 $PREFIX_PATH 环境变量的目的是什么,因为我的当前是空白的。我需要在 Ubuntu 上为我的 Enthought EPD 发行版指定什么路径来安装 python 模块。
I apologize for the relatively naive question but I am quite new to EPD on ubuntu and am still trying to figure it out.
对于这个相对幼稚的问题,我深表歉意,但我对 ubuntu 上的 EPD 还是很陌生,我仍在努力解决这个问题。
回答by user2502020
System: Ubuntu 12.04, Enthought Python Distribution (this is where I wanted to install a new python module)
系统:Ubuntu 12.04,Enthought Python Distribution(这是我想安装新python模块的地方)
So the prefix_path environment variable didn't work for me and pip still kept installing it in the default location. But I used How do I change the default directory that pip installs to?
所以 prefix_path 环境变量对我不起作用,pip 仍然将它安装在默认位置。但是我使用了 如何更改 pip 安装到的默认目录?
question as a guide. And one of the answers helped me achieve what I needed.
问题作为指导。其中一个答案帮助我实现了我所需要的。
pip install -d <path_to_my_directory>
For the path I used: path_to_epd_directory/lib/python2.7/site-packages
对于我使用的路径:path_to_epd_directory/lib/python2.7/site-packages
This puts the tar.gz file into the site-packages
这会将 tar.gz 文件放入 site-packages
Then extract it using:
然后使用以下方法提取它:
tar -zxvf pymodule.tar.gz
tar -zxvf pymodule.tar.gz
a directory named pymodule is created, cd into that module and type:
创建一个名为 pymodule 的目录,cd 进入该模块并键入:
python setup.py install
and that should do the job.
这应该可以完成工作。
回答by punchagan
Instead, you could use a copy of pipthat has been installed into your EPD installation.
相反,您可以使用pip已安装到 EPD 安装中的副本。
$ path-to-EPD/bin/enpkg pip # Or simply enpkg pip, if EPD is on your PATH.
$ path-to-EPD/bin/pip install <package-name>
回答by RayLuo
This line should work for everyone, as mentioned in the documentation.
正如文档中所述,这一行应该适用于所有人。
pip install package_name -t any/path/i/like
PS:
PS:
And to address the comment of @CPiLL, the any/path/i/likecan really be anything, such as /tmp/my-test-env. The package being installed in this way will NOTbe available for your usual python environment, in fact they will NOT even show up using pip list. And python -c "import package_name"will generally FAIL with ImportError exception, unless you cd into that folder first:
为了解决@CPiLL 的评论,实际上any/path/i/like可以是任何东西,例如/tmp/my-test-env. 以这种方式安装的软件包将不适用于您通常的 python 环境,事实上它们甚至不会使用pip list. 并且python -c "import package_name"通常会因 ImportError 异常而失败,除非您先 cd 进入该文件夹:
cd /tmp/my-test-env
python -c "import package-name"
How this technique would be useful is beyond this answer.
这种技术如何有用超出了这个答案。
回答by mahmoud alaa
This worked for me on Ubuntu Gnome 17.04. Installing PyMySQL to specific dir:
这在 Ubuntu Gnome 17.04 上对我有用。将 PyMySQL 安装到特定目录:
sudo pip install PyMySQL -t /home/mahmoud/app
回答by nguyên
This answer worked in windows OS
Short answer:To install package to the specific folder using -toption ex:pip install packageX -t lib/, then add this folder to PYTHONPAHT
此答案适用于 Windows 操作系统
简短答案:使用-t选项 ex:将软件包安装到特定文件夹pip install packageX -t lib/,然后将此文件夹添加到PYTHONPAHT
Long answer:
长答案:
install virtualenv to
.envfolderpip install with -t option, example install to lib folder of my project (named
3)(.env) d:\tmp\3>pip install packageX -t lib/show list of packages :
将 virtualenv 安装到
.env文件夹使用 -t 选项进行 pip install,例如安装到我的项目的 lib 文件夹(名为
3)(.env) d:\tmp\3>pip install packageX -t lib/显示包列表:
(.env) d:\tmp>pip list
Package Version
---------- ----------
pip 18.1
setuptools 40.6.3
...
- Not see your package ? open command-prompt as administrator right and set PYTHONPATH
- 没有看到您的包裹?以管理员权限打开命令提示符并设置 PYTHONPATH
回答by zxw
You can use this code to install you package to a specific path.
您可以使用此代码将包安装到特定路径。
pip install [package name] --target /path/to


