标签归档:pip

如何卸载使用pip install –user安装的软件包

问题:如何卸载使用pip install –user安装的软件包

--userpip 有一个选项,可以为每个用户安装Python软件包:

pip install --user [python-package-name]

我使用此选项在没有root访问权限的服务器上安装软件包。我现在需要的是在当前用户上卸载已安装的软件包。我试图执行以下命令:

pip uninstall --user [python-package-name]

但是我得到了:

no such option: --user

pip install --user除了手动查找和删除软件包外,如何卸载与之一起安装的软件包?

我发现这篇文章

pip无法从每个用户的站点软件包目录中卸载

描述了不支持从用户目录卸载软件包。根据文章,如果正确实施,则使用

pip uninstall [package-name]

安装的软件包也将在用户目录中搜索。但是对我来说仍然是一个问题。如果在系统范围和每个用户都安装了相同的软件包,该怎么办?如果有人需要针对特定​​用户目录怎么办?

There is a --user option for pip which can install a Python package per user:

pip install --user [python-package-name]

I used this option to install a package on a server for which I do not have root access. What I need now is to uninstall the installed package on the current user. I tried to execute this command:

pip uninstall --user [python-package-name]

But I got:

no such option: --user

How can I uninstall a package that I installed with pip install --user, other than manually finding and deleting the package?

I’ve found this article

pip cannot uninstall from per-user site-packages directory

which describes that uninstalling packages from user directory does not supported. According to the article if it was implemented correctly then with

pip uninstall [package-name]

the package that was installed will be also searched in user directories. But a problem still remains for me. What if the same package was installed both system-wide and per-user? What if someone needs to target a specific user directory?


回答 0

在Linux上使用Python 3.5和pip 7.1.2测试了这一情况之后,情况似乎是这样的:

  • pip install --user somepackage可以使用进行安装$HOME/.local和卸载pip uninstall somepackage

  • 无论是否somepackage同时在全系统范围内安装,都是如此。

  • 如果在两个地方都安装了该软件包,则只​​会卸载本地软件包。要使用卸载系统范围的软件包pip,请先在本地将其卸载,然后使用root特权再次运行相同的卸载命令。

  • 除了预定义的用户安装目录外,pip install --target somedir somepackage还将软件包安装到中somedir。无法使用从这样的位置卸载软件包pip。(但是在Github上实现了一个有点旧的未合并的pull请求,它实现了pip uninstall --target。)

  • 由于pip将要卸载的唯一位置是系统范围的和预定义的本地用户,因此您需要以pip uninstall相应用户身份运行才能从给定用户的本地安装目录中卸载。

Having tested this using Python 3.5 and pip 7.1.2 on Linux, the situation appears to be this:

  • pip install --user somepackage installs to $HOME/.local, and uninstalling it does work using pip uninstall somepackage.

  • This is true whether or not somepackage is also installed system-wide at the same time.

  • If the package is installed at both places, only the local one will be uninstalled. To uninstall the package system-wide using pip, first uninstall it locally, then run the same uninstall command again, with root privileges.

  • In addition to the predefined user install directory, pip install --target somedir somepackage will install the package into somedir. There is no way to uninstall a package from such a place using pip. (But there is a somewhat old unmerged pull request on Github that implements pip uninstall --target.)

  • Since the only places pip will ever uninstall from are system-wide and predefined user-local, you need to run pip uninstall as the respective user to uninstall from a given user’s local install directory.


回答 1

在MacOS上卸载软件包’oauth2client’的示例:

pip uninstall oauth2client

example to uninstall package ‘oauth2client’ on MacOS:

pip uninstall oauth2client

回答 2

但是,对于pip install --user some_pkg 在虚拟环境中使用的人员要小心。

$ path/to/python -m venv ~/my_py_venv
$ source ~/my_py_venv/bin/activate
(my_py_venv) $ pip install --user some_pkg
(my_py_venv) $ pip uninstall some_pkg
WARNING: Skipping some_pkg as it is not installed.
(my_py_venv) $ pip list
# Even `pip list` will not properly list the `some_pkg` in this case

在这种情况下,您必须停用当前的虚拟环境,然后使用相应的python/ pip可执行文件列出或卸载用户站点软件包:

(my_py_venv) $ deactivate
$ path/to/python -m pip list
$ path/to/python -m pip uninstall some_pkg

请注意,此问题是几年前报告的。似乎当前的结论是:在虚拟环境中--user无效pip,因为用户位置对于虚拟环境而言实际上没有任何意义。

Be careful though, for those who using pip install --user some_pkg inside a virtual environment.

$ path/to/python -m venv ~/my_py_venv
$ source ~/my_py_venv/bin/activate
(my_py_venv) $ pip install --user some_pkg
(my_py_venv) $ pip uninstall some_pkg
WARNING: Skipping some_pkg as it is not installed.
(my_py_venv) $ pip list
# Even `pip list` will not properly list the `some_pkg` in this case

In this case, you have to deactivate the current virtual environment, then use the corresponding python/pip executable to list or uninstall the user site packages:

(my_py_venv) $ deactivate
$ path/to/python -m pip list
$ path/to/python -m pip uninstall some_pkg

Note that this issue was reported few years ago. And it seems that the current conclusion is: --user is not valid inside a virtual env’s pip, since a user location doesn’t really make sense for a virtual environment.


回答 3

我认为可以卸载带有--userflag的软件包。这个为我工作;

pip freeze --user | xargs pip uninstall -y

对于python 3;

pip3 freeze --user | xargs pip3 uninstall -y

但是以某种方式,这些命令不会卸载setuptools和pip。在这些命令之后(如果您确实想要干净的python),可以使用以下命令删除它们:

pip uninstall setuptools && pip uninstall pip

I think it’s possible to uninstall packages installed with --user flag. This one worked for me;

pip freeze --user | xargs pip uninstall -y

For python 3;

pip3 freeze --user | xargs pip3 uninstall -y

But somehow these commands don’t uninstall setuptools and pip. After those commands (if you really want clean python) you may delete them with;

pip uninstall setuptools && pip uninstall pip


回答 4

答案尚不可行。您必须手动将其删除。

The answer is Not possible yet. You have to remove it manually.


回答 5

正如@ thomas-lotze提到的那样,由于没有相应的–user选项,当前pip工具无法执行此操作。但是我发现我可以检入〜/ .local / bin并查找特定的pip#。#,在我看来它对应于–user选项。

就我而言:

antho@noctil: ~/.l/bin$ pwd
/home/antho/.local/bin
antho@noctil: ~/.l/bin$ ls pip*
pip  pip2  pip2.7  pip3  pip3.5

然后只需卸载特定的pip版本即可。

As @thomas-lotze has mentioned, currently pip tooling does not do that as there is no corresponding –user option. But what I find is that I can check in ~/.local/bin and look for the specific pip#.# which looks to me like it corresponds to the –user option.

In my case:

antho@noctil: ~/.l/bin$ pwd
/home/antho/.local/bin
antho@noctil: ~/.l/bin$ ls pip*
pip  pip2  pip2.7  pip3  pip3.5

And then just uninstall with the specific pip version.


回答 6

我正在运行Anaconda 4.3.22版和python3.6.1环境,并且遇到了此问题。这是历史记录和修复方法:

pip uninstall opencv-python # -- the original step. failed.

ImportError: DLL load failed: The specified module could not be found.

我在python3.6环境中执行了此操作,并收到此错误。

python -m pip install opencv-python # same package as above.
conda install -c conda-forge opencv # separate install parallel to opencv
pip-install opencv-contrib-python # suggested by another user here. doesn't resolve it.

接下来,我尝试下载python3.6并将python3.dll放入该文件夹和各个文件夹中。没有改变。

最后,它解决了:

pip uninstall opencv-python

(仍然安装了另一个conda-forge版本)。这仅留下了conda版本,并且在3.6版本中有效。

>>>import cv2
>>>

加工!

I am running Anaconda version 4.3.22 and a python3.6.1 environment, and had this problem. Here’s the history and the fix:

pip uninstall opencv-python # -- the original step. failed.

ImportError: DLL load failed: The specified module could not be found.

I did this into my python3.6 environment and got this error.

python -m pip install opencv-python # same package as above.
conda install -c conda-forge opencv # separate install parallel to opencv
pip-install opencv-contrib-python # suggested by another user here. doesn't resolve it.

Next, I tried downloading python3.6 and putting the python3.dll in the folder and in various folders. nothing changed.

finally, this fixed it:

pip uninstall opencv-python

(the other conda-forge version is still installed) This left only the conda version, and that works in 3.6.

>>>import cv2
>>>

working!


启动器中的致命错误:无法使用“” C:\ Program Files(x86)\ Python33 \ python.exe”来创建进程。“ C:\ Program Files(x86)\ Python33 \ pip.exe”

问题:启动器中的致命错误:无法使用“” C:\ Program Files(x86)\ Python33 \ python.exe”来创建进程。“ C:\ Program Files(x86)\ Python33 \ pip.exe”

搜索网络似乎是由Python安装路径中的空格引起的问题。

我如何pip才能工作而不必在没有空格的路径中重新安装所有内容?

Searching the net this seems to be a problem caused by spaces in the Python installation path.

How do I get pip to work without having to reinstall everything in a path without spaces ?


回答 0

看起来

python -m pip install XXX 

无论如何都会为我工作(请参阅user474491的链接

it seems that

python -m pip install XXX 

will work anyway (worked for me) (see link by user474491)


回答 1

至少在Windows上,pip将安装后的执行路径存储在可执行文件中pip.exe

使用十六进制编辑器或写字板编辑此文件(您必须将其保存为纯文本然后保留二进制数据),使用引号和空格将Python路径更改为如下所示:

#!"C:\Program Files (x86)\Python33\python.exe"

到没有空格和引号的转义路径,并以空格填充(末尾的点应为空格):

#!C:\Progra~2\Python33\python.exe.............

对于“ C:\ Program Files”,此路径可能是“ C:\ Progra〜1”(在DOS / Windows 3.x表示法中,缩短的路径名使用波浪号和数字)。Windows提供了此备用符号,以便与DOS / Windows 3.x应用程序向后兼容。

请注意,由于这是一个二进制文件,因此不应更改可能会破坏可执行文件的文件大小,因此可能会导致填充。

使用管理员权限进行保存,请确保将其实际保存在目标位置,然后重试。

您可能还需要将PATH变量设置为使用~指向路径的符号pip

On Windows at least, pip stores the execution path in the executable pip.exe when it is installed.

Edit this file using a hex editor or WordPad (you have to save it as plain text then to retain binary data), change the path to Python with quotes and spaces like this:

#!"C:\Program Files (x86)\Python33\python.exe"

to an escaped path without spaces and quotes and pad with spaces (dots at the end should be spaces):

#!C:\Progra~2\Python33\python.exe.............

For “C:\Program Files”, this path would probably be “C:\Progra~1” (shortened path names in DOS / Windows 3.x notation use tilde and numbers). Windows provides this alternative notation for backwards compatibility with DOS / Windows 3.x apps.

Note that as this is a binary file, you should not change the file size which may break the executable, hence the padding.

Save with administrator privileges, make sure it is actually saved at the target location and try again.

You might also need to set the PATH variable to use the ~ notation for the path to pip.


回答 2

与我在https://pip.pypa.io/en/latest/installing.html#install-pip中阅读的要更新pip的问题相同:

python -m pip install -U pip

所以我做了(例如)

python -m pip install virtualenv

而且有效!因此,您可以通过“ virtualenv”另一个所需的软件包来执行相同的操作。

having the same trouble I read in https://pip.pypa.io/en/latest/installing.html#install-pip that to update pip it’s:

python -m pip install -U pip

So I made (for example)

python -m pip install virtualenv

And it worked! So you can do the same being ‘virtualenv’ another package you want.


回答 3

python -m pip

确实可以解决问题Fatal error in launcher: Unable to create process using '"'。在Windows 10上工作

python -m pip

really works for the problem Fatal error in launcher: Unable to create process using '"'.Worked on Windows 10


回答 4

我有一个类似的问题,升级点对我来说已经解决了。

python -m pip install --upgrade pip 

这是在Windows上,pip.exe中的python路径不正确。有关路径的更多信息,请参见Archimedix答案

I had a similar issue and upgrading pip fixed it for me.

python -m pip install --upgrade pip 

This was on Windows and the path to python inside pip.exe was incorrect. See Archimedix answer for more information about the path.


回答 5

这是我解决的方法:

  1. pip.exe在7zip中打开并解压缩__main__.py到Python \ Scripts文件夹。

    就我而言 C:\Program Files (x86)\Python27\Scripts

  2. 重命名__main__.pypip.py

  3. 运行! python pip.py install something

编辑:

如果您希望能够pip install something从任何地方进行操作,也可以执行以下操作:

  1. 将pip.py重命名为pip2.py(以避免导入pip错误)

  2. 使C:\Program Files (x86)\Python27\pip.bat具有以下内容:

python“ C:\ Program Files(x86)\ Python27 \ Scripts \ pip2.py”%1%2%3%4%5%6%7%8%9

  1. 添加C:\Program Files (x86)\Python27到您的PATH(如果尚未添加)

  2. 运行! pip install something

Here’s how I solved it:

  1. open pip.exe in 7zip and extract __main__.py to Python\Scripts folder.

    In my case it was C:\Program Files (x86)\Python27\Scripts

  2. Rename __main__.py to pip.py

  3. Run it! python pip.py install something

EDIT:

If you want to be able to do pip install something from anywhere, do this too:

  1. rename pip.py to pip2.py (to avoid import pip errors)

  2. make C:\Program Files (x86)\Python27\pip.bat with the following contents:

python “C:\Program Files (x86)\Python27\Scripts\pip2.py” %1 %2 %3 %4 %5 %6 %7 %8 %9

  1. add C:\Program Files (x86)\Python27 to your PATH (if is not already)

  2. Run it! pip install something


回答 6

当路径中有空格时,这是一个已知的错误virtualenv。已进行更正,并将在下一版本中可用。

This is a known Bug when there is a space in the virtualenv path. Correction has been made, and will be available in the next version.


回答 7

我有同样的问题,并使用以下方法进行了点升级,现在效果很好。 python -m pip install --upgrade pip

i had same issue and did a pip upgrade using following and now it works fine. python -m pip install --upgrade pip


回答 8

我写了一个脚本来修补那些exe。但是最好的方法是修复distutil本身。

"""Fix "Fatal error in launcher: Unable to create process using ..." error. Put me besides those EXE made by pip. (They are made by distutils, and used by pip)"""
import re
import sys
import os
from glob import glob


script_path = os.path.dirname(os.path.realpath(__file__))
real_int_path = sys.executable
_t = script_path.rpartition(os.sep)[0] + os.sep + 'python.exe'
if script_path.lower().endswith('scripts') and os.path.isfile(_t):
    real_int_path = _t

print('real interpreter path: ' + real_int_path)
print()

for i in glob('*.exe'):
    with open(i, 'rb+') as f:
        img = f.read()
        match = re.search(rb'#![a-zA-Z]:\\.+\.exe', img)
        if not match:
            print("can't fix file: " + i)
            continue
        int_path = match.group()[2:].decode()
        int_path_start = match.start() + 2
        int_path_end = match.end()

        if int_path.lower() == real_int_path.lower():
            continue
        print('fix interpreter path: %s in %s' % (int_path, i))
        f.seek(int_path_start)
        f.write(real_int_path.encode())
        f.write(img[int_path_end:])

I wrote a script to patch those exe. But the best way is to fix distutil itself.

"""Fix "Fatal error in launcher: Unable to create process using ..." error. Put me besides those EXE made by pip. (They are made by distutils, and used by pip)"""
import re
import sys
import os
from glob import glob


script_path = os.path.dirname(os.path.realpath(__file__))
real_int_path = sys.executable
_t = script_path.rpartition(os.sep)[0] + os.sep + 'python.exe'
if script_path.lower().endswith('scripts') and os.path.isfile(_t):
    real_int_path = _t

print('real interpreter path: ' + real_int_path)
print()

for i in glob('*.exe'):
    with open(i, 'rb+') as f:
        img = f.read()
        match = re.search(rb'#![a-zA-Z]:\\.+\.exe', img)
        if not match:
            print("can't fix file: " + i)
            continue
        int_path = match.group()[2:].decode()
        int_path_start = match.start() + 2
        int_path_end = match.end()

        if int_path.lower() == real_int_path.lower():
            continue
        print('fix interpreter path: %s in %s' % (int_path, i))
        f.seek(int_path_start)
        f.write(real_int_path.encode())
        f.write(img[int_path_end:])

回答 9

我在Windows 10上遇到了相同的问题,尝试了所有先前的解决方案后问题仍然存在,所以我决定卸载python 2.7并安装2.7.13版,它可以完美运行。

I had the same issue on windows 10, after trying all the previous solution the problem persists so I decided to uninstall my python 2.7 and install the version 2.7.13 and it works perfectly.


回答 10

如果在Windows上使用区分大小写的文件系统,则可能会发生这种情况。您可以判断是否存在目录中的lib目录和目录:Libvenv

> dir

Directory: C:\git\case\sensitive\filesystem\here\venv

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        4/07/2018   4:10 PM                Include
d-----       22/01/2019   7:52 AM                Lib
d-----       22/01/2019   7:52 AM                lib
d-----       22/01/2019   7:52 AM                Scripts
d-----       22/01/2019   7:52 AM                tcl

要解决此问题(直到virtualenv.py得到解决:https : //github.com/pypa/virtualenv/issues/935),请合并两个lib目录并使venv大小写不敏感:

cd venv
move Lib rmthis
move .\rmthis\site-packages\ lib
rmdir rmthis
fsutil.exe file setCaseSensitiveInfo . disable

This can happen if you are using a case-sensitive file system on Windows. You can tell if this is the case if there is both a lib directory and a Lib directory in your venv directory :

> dir

Directory: C:\git\case\sensitive\filesystem\here\venv

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        4/07/2018   4:10 PM                Include
d-----       22/01/2019   7:52 AM                Lib
d-----       22/01/2019   7:52 AM                lib
d-----       22/01/2019   7:52 AM                Scripts
d-----       22/01/2019   7:52 AM                tcl

To workaround this (until virtualenv.py gets fixed: https://github.com/pypa/virtualenv/issues/935) merge the two lib directories and make venv case-insensitive:

cd venv
move Lib rmthis
move .\rmthis\site-packages\ lib
rmdir rmthis
fsutil.exe file setCaseSensitiveInfo . disable

回答 11

请添加此地址:

C:\ Program文件(x86)\ Python33

在Windows PATH变量中

尽管首先确保这是Python exe文件所在的文件夹,然后才将此路径添加到PATH变量。

要在PATH变量中附加地址,请转到

控制面板->系统->高级系统设置->环境变量->系统变量->路径->编辑->

然后附加上述路径并点击保存

Please add this address :

C:\Program Files (x86)\Python33

in Windows PATH Variable

Though first make sure this is the folder where Python exe file resides, then only add this path to the PATH variable.

To append addresses in PATH variable, Please go to

Control Panel -> Systems -> Advanced System Settings -> Environment Variables -> System Variables -> Path -> Edit ->

Then append the above mentioned path & click Save


回答 12

改名的可执行python.exe到如python27.exe。关于Archimedix的答案,我使用十六进制编辑器打开了pip.exe ,滚动到文件末尾,python.exe并将路径更改为python27.exe。在进行编辑时,请不要忽略其他信息。

I renamed the executable of python.exe to e.g. python27.exe. In respect to the answer of Archimedix I opened my pip.exe with a Hex-Editor, scrolled to the end of the file and changed the python.exe in the path to python27.exe. While editing make shure you don’t override other informations.


回答 13

我添加了anwer,因为在本地配置ODDO9源代码时遇到了相同的错误,并且在运行exe时需要exe才能运行,我也遇到了相同的错误。

从昨天开始,我就配置了oddo 9.0(部分:-“在requirements.txt文件中列出的Python依赖项。”),并且需要以如下方式运行PIP exe:

C:\ YourOdooPath> C:\ Python27 \ Scripts \ pip.exe安装-r requirements.txt

我的奇怪路径是:-D:\ Program Files(x86)\ Odoo 9.0-20151014我的pip位置是:-D:\ Program Files(x86)\ Python27 \ Scripts \ pip.exe

因此,我打开命令提示符并转到上面的奇怪路径,并尝试使用这些组合运行pip exe,但始终没有给出以上错误。

  1. D:\ Program Files(x86)\ Python27 \ Scripts \ pip.exe安装-r requirements.txt
  2. “ D:\ Program Files(x86)\ Python27 \ Scripts \ pip.exe安装-r requirements.txt” Python27 \ Scripts \ pip.exe安装-r requirements.txt

  3. “ Python27 / Scripts / pip.exe安装-r requirements.txt”

我通过@ user4154243回答解决了我的问题,谢谢。

步骤1:添加变量(如果您的路径不在变量的路径中)。

步骤2:进入命令提示符,打开安装路径。

步骤3:运行此命令python -m pip install XXX将运行并安装东西。

I added my anwer because I have getting the same error while configure ODDO9 source code in local and its need the exe to run while run exe, I got the same error.

From yesterday I was configure oddo 9.0 (section :- “Python dependencies listed in the requirements.txt file.”) and its need to run PIP exe as

C:\YourOdooPath> C:\Python27\Scripts\pip.exe install -r requirements.txt

My oddo path is :- D:\Program Files (x86)\Odoo 9.0-20151014 My pip location is :- D:\Program Files (x86)\Python27\Scripts\pip.exe

So I open command prompt and go to above oddo path and try to run pip exe with these combination, but not given always above error.

  1. D:\Program Files (x86)\Python27\Scripts\pip.exe install -r requirements.txt
  2. “D:\Program Files (x86)\Python27\Scripts\pip.exe install -r requirements.txt” Python27\Scripts\pip.exe install -r requirements.txt

  3. “Python27/Scripts/pip.exe install -r requirements.txt”

I resolved my issue by the @user4154243 answer, thanks for that.

Step 1: Add variable(if your path is not comes in variable’s path).

Step 2: Go to command prompt, open oddo path where you installed.

Step 3: run this command python -m pip install XXX will run and installed the things.


回答 14

如果您同时安装我在Window中解决了我的问题 python2和python3,

您需要输入某人\脚本将所有file.exe更改为file27.exe,然后解决

我的D:\ Python27 \ Scripts将django-admin.exe编辑为django-admin27.exe从而完成了

i solve my problem in Window if u install both python2 and python3

u need enter someone \Scripts change all file.exe to file27.exe,then it solve

my D:\Python27\Scripts edit django-admin.exe to django-admin27.exe so it done


回答 15

我的确切问题是(在启动器中出现致命错误:无法使用’“’创建进程)在Windows 10上。所以我导航至” C:\ Python33 \ Lib \ site-packages“并删除了django文件夹和pip文件夹,然后重新安装了django使用点,我的问题就解决了。

My exact problem was (Fatal error in launcher: Unable to create process using ‘”‘) on windows 10. So I navigated to the “C:\Python33\Lib\site-packages” and deleted django folder and pip folders then reinstalled django using pip and my problem was solved.


回答 16

我选择不为所有用户安装Windows(64位)Python,而是为我安装。

重新安装Python-x64并检查“针对所有用户”的高级选项为我解决了pip问题。

I have chosen to install Python for Windows (64bit) not for all users, but just for me.

Reinstalling Python-x64 and checking the advanced option “for all users” solved the pip problem for me.


回答 17

这是我固定的方法。

  1. 下载https://bootstrap.pypa.io/get-pip.py
  2. 活跃你的活力
  3. 导航至get-pip.py文件,然后键入“ python get-pip.py”(不带引号)。

它将在环境中重新安装您的pip并自动卸载以前的版本。

现在繁荣!安装任何您喜欢的东西

Here is how i fixed it.

  1. Download https://bootstrap.pypa.io/get-pip.py
  2. Active your vitualenv
  3. Navigate to the get-pip.py file and type “python get-pip.py” without quote.

it will reinstall your pip within the environment and uninstall the previous version automatically.

now boom!! install whatever you like


回答 18

尝试使用以下链接重新安装,

下载https://bootstrap.pypa.io/get-pip.py

下载后,将“ get-pip.py”复制到python安装的主目录中,然后打开cmd并导航到python目录并键入“ python get-pip.py”(不带引号)

注意:还要确保在环境变量中设置了python目录。

希望这会有所帮助。

Try reinstall by using the below link,

Download https://bootstrap.pypa.io/get-pip.py

After download, copy the “get-pip.py” to python installed main dirctory, then open cmd and navigate to python directory and type “python get-pip.py” (without quotes)

Note: Also make sure the python directory is set in the environmental variable.

Hope this might help.


回答 19

对我来说,当我将环境路径更改为指向v2.7时出现了这个问题,该路径最初指向v3.6。之后,要运行pipvirtualenv命令,我必须python -m pip install XXX按照以下答案中的说明进行操作。

因此,为了摆脱这种情况,我再次运行v2.7安装程序,选择了change选项,并确保启用了“ 添加到路径”选项,然后运行安装程序。之后,一切都会正常进行。

For me this problem appeared when I changed the environment path to point to v2.7 which was initially pointing to v3.6. After that, to run pip or virtualenv commands, I had to python -m pip install XXX as mentioned in the answers below.

So, in order to get rid of this, I ran the v2.7 installer again, chose change option and made sure that, add to path option was enabled, and let the installer run. After that everything works as it should.


回答 20

我遇到了这个问题,并且此页面上的其他修复没有完全解决问题。

解决问题的方法是进入我的系统环境变量并查看PATH-我已经卸载了Python 3,但是Python 3文件夹的旧路径仍然存在。我在PC上仅运行Python 2,并使用Python 2安装pip。

除了升级到最新版本以外,还从PATH中删除对不存在的Python 3文件夹的引用pip

I had this issue and the other fixes on this page didn’t fully solve the problem.

What did solve the problem was going in to my system environment variables and looking at the PATH – I had uninstalled Python 3 but the old path to the Python 3 folder was still there. I’m running only Python 2 on my PC and used Python 2 to install pip.

Deleting the references to the nonexistent Python 3 folders from PATH in addition to upgrading to the latest version of pip fixed the issue.


回答 21

我有一个更简单的解决方案。使用@apple方式,但将main .py 重命名为pip.py,然后将其放在python版本的scripts文件夹中,并将scripts文件夹添加到您的路径中以全局访问它。如果您不想将其添加到路径,则必须将其cd到脚本,然后运行pip命令。

I had a simpler solution. Using @apple way but rename main.py to pip.py then put it in your python version scripts folder and add scripts folder to your path access it globally. if you don’t want to add it to path you have to cd to scripts and then run pip command.


回答 22

Windows上我通过以下方式解决了此问题:

1)卸载Python

2)导航到C:\Users\MyName\AppData\Local\Programs(您应该打开隐藏文件的可见性,显示隐藏文件的说明

3)删除“ Python”文件夹

4)安装Python

On Windows I had solved this problem in the following way :

1) uninstalled Python

2) navigated to C:\Users\MyName\AppData\Local\Programs(your should turn on hidden files visibility Show hidden files instruction)

3) deleted ‘Python’ folder

4) installed Python


回答 23

通过卸载python3.7和安装python3.8重新安装python时,我遇到类似的问题。但是我通过删除先前版本的python目录解决了。对我来说它就在这里

C:\ Users \您的用户名\ AppData \ Local \ Programs \ Python

我删除了名为Python37的文件夹(对于以前的版本),并保留了Python38(对于更新的版本)。之所以有用,是因为python本身似乎很难为您的python脚本找到正确的目录。

I have similar problem when I reinstall my python, by uninstalling python3.7 and installing python3.8. But I solved it by removing the previous version of python directory. For me it was located here,

C:\Users\your-username\AppData\Local\Programs\Python

I deleted the folder named Python37 (for previous version) and keep Python38 (for updated version). This worked because python itself seems having a trouble on finding the right directory for your python scripts.


回答 24

我试图安装一些站点软件包,例如numpy,xgboost等,但是每次都会显示此错误:

Fatal error in launcher: Unable to create process using

我尝试了多种方法来解决此问题,并找到了一个成功地帮助了我的方法:

python -m pip freeze

希望它也能帮助别人。

PS我在这里找到了这个解决方案:https : //stackoverflow.com/a/39733705/10310794

I was trying to install some site-packages like numpy, xgboost and so on, but this error showed up every time:

Fatal error in launcher: Unable to create process using

I’ve tried many ways to solve this problem and found this one, that successfully helped me:

python -m pip freeze

Hope it’ll help someone too.

P.S. I found this solution here: https://stackoverflow.com/a/39733705/10310794


回答 25

您可以从PC删除先前的python文件夹以及环境变量路径,然后重新安装python。它将解决

You can remove previous python folder and also environment variable path from you pc then Reinstall python .it will be solve


回答 26

而不是直接调用ipython,而是使用诸如

$ python“ ipython.exe的完整路径”

Instead of calling ipython directly, it is loaded using Python such as

$ python “full path to ipython.exe”


用pip安装SciPy

问题:用pip安装SciPy

使用可以通过pip安装NumPypip install numpy

SciPy是否有类似的可能性?(这样pip install scipy做无效。)


更新资料

SciPy软件包现在可以安装了pip

It is possible to install NumPy with pip using pip install numpy.

Is there a similar possibility with SciPy? (Doing pip install scipy does not work.)


Update

The package SciPy is now available to be installed with pip!


回答 0

试图easy_install指出其在Python Package Index中列出的问题,该点会进行搜索。

easy_install scipy
Searching for scipy
Reading http://pypi.python.org/simple/scipy/
Reading http://www.scipy.org
Reading http://sourceforge.net/project/showfiles.php?group_id=27747&package_id=19531
Reading http://new.scipy.org/Wiki/Download

但是,一切并没有丢失。pip可以从Subversion(SVN),GitMercurialBazaar存储库安装。SciPy使用SVN:

pip install svn+http://svn.scipy.org/svn/scipy/trunk/#egg=scipy

更新(12-2012):

pip install git+https://github.com/scipy/scipy.git

由于NumPy是依赖项,因此也应安装它。

An attempt to easy_install indicates a problem with their listing in the Python Package Index, which pip searches.

easy_install scipy
Searching for scipy
Reading http://pypi.python.org/simple/scipy/
Reading http://www.scipy.org
Reading http://sourceforge.net/project/showfiles.php?group_id=27747&package_id=19531
Reading http://new.scipy.org/Wiki/Download

All is not lost, however; pip can install from Subversion (SVN), Git, Mercurial, and Bazaar repositories. SciPy uses SVN:

pip install svn+http://svn.scipy.org/svn/scipy/trunk/#egg=scipy

Update (12-2012):

pip install git+https://github.com/scipy/scipy.git

Since NumPy is a dependency, it should be installed as well.


回答 1

先决条件:

sudo apt-get install build-essential gfortran libatlas-base-dev python-pip python-dev
sudo pip install --upgrade pip

实际包装:

sudo pip install numpy
sudo pip install scipy

可选软件包:

sudo pip install matplotlib   OR  sudo apt-get install python-matplotlib
sudo pip install -U scikit-learn
sudo pip install pandas

src

Prerequisite:

sudo apt-get install build-essential gfortran libatlas-base-dev python-pip python-dev
sudo pip install --upgrade pip

Actual packages:

sudo pip install numpy
sudo pip install scipy

Optional packages:

sudo pip install matplotlib   OR  sudo apt-get install python-matplotlib
sudo pip install -U scikit-learn
sudo pip install pandas

src


回答 2

在Ubuntu 10.04(Lucid)中,pip install scipy安装某些依赖项后,我可以成功地(在virtualenv中):

$ sudo apt-get install libamd2.2.0 libblas3gf libc6 libgcc1 libgfortran3 liblapack3gf libumfpack5.4.0 libstdc++6 build-essential gfortran libatlas-sse2-dev python-all-dev

In Ubuntu 10.04 (Lucid), I could successfully pip install scipy (within a virtualenv) after installing some of its dependencies, in particular:

$ sudo apt-get install libamd2.2.0 libblas3gf libc6 libgcc1 libgfortran3 liblapack3gf libumfpack5.4.0 libstdc++6 build-essential gfortran libatlas-sse2-dev python-all-dev

回答 3

要在Windows上安装scipy,请遵循以下说明:-

步骤1:按此链接http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy下载scipy .whl文件(例如scipy-0.17.0-cp34-none-win_amd64.whl)。

步骤2:从命令提示符(cd folder-name)转到下载文件所在的目录。

步骤3:运行以下命令:

pip install scipy-0.17.0-cp27-none-win_amd64.whl

To install scipy on windows follow these instructions:-

Step-1 : Press this link http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy to download a scipy .whl file (e.g. scipy-0.17.0-cp34-none-win_amd64.whl).

Step-2: Go to the directory where that download file is there from the command prompt (cd folder-name ).

Step-3: Run this command:

pip install scipy-0.17.0-cp27-none-win_amd64.whl

回答 4

我尝试了以上所有方法,但对我没有任何帮助。这解决了我所有的问题:

pip install -U numpy

pip install -U scipy

请注意,-U用于pip install请求升级软件包的选项。没有它,如果已经安装了软件包,pip则会通知您此信息,并且不做任何事情就退出。

I tried all the above and nothing worked for me. This solved all my problems:

pip install -U numpy

pip install -U scipy

Note that the -U option to pip install requests that the package be upgraded. Without it, if the package is already installed pip will inform you of this and exit without doing anything.


回答 5

如果我首先将BLAS,LAPACK和GCC Fortran作为系统软件包安装(我正在使用Arch Linux),则可以通过以下方式安装SciPy:

pip install scipy

If I first install BLAS, LAPACK and GCC Fortran as system packages (I’m using Arch Linux), I can get SciPy installed with:

pip install scipy

回答 6

在Fedora上,这有效:

sudo yum install -y python-pip
sudo yum install -y lapack lapack-devel blas blas-devel 
sudo yum install -y blas-static lapack-static
sudo pip install numpy
sudo pip install scipy

如果public key下载时出现任何错误,请将--nogpgcheck作为参数添加到yum,例如: yum --nogpgcheck install blas-devel

从Fedora 23开始,使用dnf代替yum

On Fedora, this works:

sudo yum install -y python-pip
sudo yum install -y lapack lapack-devel blas blas-devel 
sudo yum install -y blas-static lapack-static
sudo pip install numpy
sudo pip install scipy

If you get any public key errors while downloading, add --nogpgcheck as parameter to yum, for example: yum --nogpgcheck install blas-devel

On Fedora 23 onwards, use dnf instead of yum.


回答 7

对于Arch Linux用户:

pip install --user scipy 先决条件要安装以下Arch软件包:

  • gcc-fortran
  • blas
  • lapack

For the Arch Linux users:

pip install --user scipy prerequisites the following Arch packages to be installed:

  • gcc-fortran
  • blas
  • lapack

回答 8

适用于Ubuntu(Ubuntu 10.04 LTS(Lucid Lynx))的插件:

存储库已移动,但是

pip install -e git+http://github.com/scipy/scipy/#egg=scipy

我失败了…通过以下步骤,最终解决了问题(作为虚拟环境中的root,python3指向Python 3.2.2的链接):安装Ubuntu依赖项(请参阅elaichi),克隆NumPy和SciPy:

git clone git://github.com/scipy/scipy.git scipy

git clone git://github.com/numpy/numpy.git numpy

生成NumPy(在numpy文件夹中):

python3 setup.py build --fcompiler=gnu95

安装SciPy(在scipy文件夹中):

python3 setup.py install

Addon for Ubuntu (Ubuntu 10.04 LTS (Lucid Lynx)):

The repository moved, but a

pip install -e git+http://github.com/scipy/scipy/#egg=scipy

failed for me… With the following steps, it finally worked out (as root in a virtual environment, where python3 is a link to Python 3.2.2): install the Ubuntu dependencies (see elaichi), clone NumPy and SciPy:

git clone git://github.com/scipy/scipy.git scipy

git clone git://github.com/numpy/numpy.git numpy

Build NumPy (within the numpy folder):

python3 setup.py build --fcompiler=gnu95

Install SciPy (within the scipy folder):

python3 setup.py install

回答 9

就我而言,直到我还安装了以下软件包,该软件包才起作用:libatlas-base-dev,gfortran

 sudo apt-get install libatlas-base-dev gfortran

然后运行pip install scipy

In my case, it wasn’t working until I also installed the following package : libatlas-base-dev, gfortran

 sudo apt-get install libatlas-base-dev gfortran

Then run pip install scipy


回答 10

  1. 安装python-3.4.4
  2. scipy-0.15.1-win32-superpack-python3.4
  3. 应用以下推荐文档
py -m pip install --upgrade pip
py -m pip install numpy
py -m pip install matplotlib
py -m pip install scipy
py -m pip install scikit-learn
  1. install python-3.4.4
  2. scipy-0.15.1-win32-superpack-python3.4
  3. apply the following commend doc
py -m pip install --upgrade pip
py -m pip install numpy
py -m pip install matplotlib
py -m pip install scipy
py -m pip install scikit-learn

回答 11

答案是肯定的。

首先,您可以轻松安装numpy use命令:

pip install numpy

然后,您应该安装Scipy所需的mkl,然后可以在此处下载

下载file_name.whl后,您进行安装

C:\Users\****\Desktop\a> pip install mkl_service-1.1.2-cp35-cp35m-win32.whl
Processing c:\users\****\desktop\a\mkl_service-1.1.2-cp35-cp35m-win32.whl 
Installing collected packages: mkl-service    
Successfully installed mkl-service-1.1.2

然后,您可以在同一网站上下载scipy-0.18.1-cp35-cp35m-win32.whl

注意:您应该根据您的python版本下载file_name.whl,如果您的python版本是32bit python3.5,则应该下载该文件,而“ win32”是您的python版本,而不是操作系统版本。

然后像这样安装file_name.whl:

C:\Users\****\Desktop\a>pip install scipy-0.18.1-cp35-cp35m-win32.whl
Processing c:\users\****\desktop\a\scipy-0.18.1-cp35-cp35m-win32.whl
Installing collected packages: scipy
Successfully installed scipy-0.18.1

然后,只有一件事要做:注释掉特定的一行,否则当您输入命令“ import scipy”时会出现错误消息。

所以注释掉这行

from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl

在此文件中:your_own_path \ lib \ site-packages \ scipy__init __。py

然后您可以使用SciPy :)

这里告诉您更多有关最后一步的信息。

是一个类似问题的答案。

The answer is yes, there is.

First you can easily install numpy use commands:

pip install numpy

Then you should install mkl, which is required by Scipy, and you can download it here

After download the file_name.whl you install it

C:\Users\****\Desktop\a> pip install mkl_service-1.1.2-cp35-cp35m-win32.whl
Processing c:\users\****\desktop\a\mkl_service-1.1.2-cp35-cp35m-win32.whl 
Installing collected packages: mkl-service    
Successfully installed mkl-service-1.1.2

Then at the same website you can download scipy-0.18.1-cp35-cp35m-win32.whl

Note:You should download the file_name.whl according to you python version, if you python version is 32bit python3.5 you should download this one, and the “win32” is about your python version, not your operating system version.

Then install file_name.whl like this:

C:\Users\****\Desktop\a>pip install scipy-0.18.1-cp35-cp35m-win32.whl
Processing c:\users\****\desktop\a\scipy-0.18.1-cp35-cp35m-win32.whl
Installing collected packages: scipy
Successfully installed scipy-0.18.1

Then there is only one more thing to do: comment out a specfic line or there will be error messages when you imput command “import scipy”.

So comment out this line

from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl

in this file: your_own_path\lib\site-packages\scipy__init__.py

Then you can use SciPy :)

Here tells you more about the last step.

Here is a similar anwser to a similar question.


回答 12

除了所有这些答案之外,如果在64位计算机上安装32位python,则无论您的计算机如何,都必须下载32位scipy。 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 在上述URL中,您可以下载软件包,命令为:pip install

Besides all of these answers, If you install python of 32bit on your 64bit machine, you have to download scipy of 32-bit irrespective of your machine. http://www.lfd.uci.edu/~gohlke/pythonlibs/ In the above URL you can download the packages and command is: pip install


回答 13

对于gentoo,它位于主存储库中: emerge --ask scipy

For gentoo, it’s in the main repository: emerge --ask scipy


回答 14

您也可以在Windows中使用python 3.6使用它 python -m pip install scipy

You can also use this in windows with python 3.6 python -m pip install scipy


在virtualenv中升级python

问题:在virtualenv中升级python

有没有一种方法可以升级virtualenv中使用的python版本(例如,如果出现错误修复版本)?

我可以pip freeze --local > requirements.txt删除目录和pip install -r requirements.txt,但这需要大量重新安装大型库,例如,numpy我经常使用。

我可以看到从2.6-> 2.7升级时这是一个优势,但是2.7.x-> 2.7.y呢?

Is there a way to upgrade the version of python used in a virtualenv (e.g. if a bugfix release comes out)?

I could pip freeze --local > requirements.txt, then remove the directory and pip install -r requirements.txt, but this requires a lot of reinstallation of large libraries, for instance, numpy, which I use a lot.

I can see this is an advantage when upgrading from, e.g., 2.6 -> 2.7, but what about 2.7.x -> 2.7.y?


回答 0

你看到吗?如果我没有误解这个答案,您可以尝试在旧版本的基础上创建一个新的virtualenv。您只需要知道哪个python将使用您的virtualenv(您将需要查看您的virtualenv版本)。

如果您的virtualenv安装了与旧版本相同的python版本,并且无法升级virtualenv软件包,则可能需要阅读此内容,以便使用所需的python版本安装virtualenv。

编辑

我已经测试了这种方法(在旧方法的基础上创建新的virtualenv的方法),它对我来说很好用。我认为,如果您从python 2.6更改为2.7或从2.7更改为3.x,则可能会遇到一些问题,但是如果您在同一版本内升级(保持在2.7不变),则不会有任何问题,因为所有软件包对于两个python版本,它们都位于相同的文件夹中(2.7.x和2.7.y软件包位于your_env / lib / python2.7 /中)。

如果更改了virtualenv python版本,则需要再次安装该版本的所有软件包(或仅将所需的软件包链接到新版本的packages文件夹中,即:your_env / lib / python_newversion / site-packages)

Did you see this? If I haven’t misunderstand that answer, you may try to create a new virtualenv on top of the old one. You just need to know which python is going to use your virtualenv (you will need to see your virtualenv version).

If your virtualenv is installed with the same python version of the old one and upgrading your virtualenv package is not an option, you may want to read this in order to install a virtualenv with the python version you want.

EDIT

I’ve tested this approach (the one that create a new virtualenv on top of the old one) and it worked fine for me. I think you may have some problems if you change from python 2.6 to 2.7 or 2.7 to 3.x but if you just upgrade inside the same version (staying at 2.7 as you want) you shouldn’t have any problem, as all the packages are held in the same folders for both python versions (2.7.x and 2.7.y packages are inside your_env/lib/python2.7/).

If you change your virtualenv python version, you will need to install all your packages again for that version (or just link the packages you need into the new version packages folder, i.e: your_env/lib/python_newversion/site-packages)


回答 1

如果您恰巧使用的是Python 3.3+随附的venv模块,则它支持一个--upgrade选项。根据文档

假设Python已就地升级,请升级环境目录以使用此版本的Python

python3 -m venv --upgrade ENV_DIR

If you happen to be using the venv module that comes with Python 3.3+, it supports an --upgrade option. Per the docs:

Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place

python3 -m venv --upgrade ENV_DIR

回答 2

再次更新: 以下方法在较新版本的virtualenv中可能不起作用。在尝试对旧版virtualenv进行修改之前,应将依赖项保存在需求文件(pip freeze > requirements.txt)中,并在其他位置进行备份。如果有任何问题,您仍然可以创建一个新的virtualenv并在其中安装旧的依赖项(pip install -r requirements.txt)。

更新:我最初回答5个月后就更改了答案。以下方法更方便,更可靠。

副作用:在将Python升级到v2.7.8之后在虚拟环境中Symbol not found: _SSLv2_method执行操作时,它还修复了异常import ssl

注意:目前,这仅适用于Python2.7.x


如果您在OS X上使用Homebrew Python,请首先使用deactivate所有virtualenv,然后升级Python:

brew update && brew upgrade python

运行以下命令(<EXISTING_ENV_PATH>是您的虚拟环境的路径):

cd <EXISTING_ENV_PATH>
rm .Python
rm bin/pip{,2,2.7}
rm bin/python{,2,2.7}
rm -r include/python2.7
rm lib/python2.7/*
rm -r lib/python2.7/distutils
rm lib/python2.7/site-packages/easy_install.*
rm -r lib/python2.7/site-packages/pip
rm -r lib/python2.7/site-packages/pip-*.dist-info
rm -r lib/python2.7/site-packages/setuptools
rm -r lib/python2.7/site-packages/setuptools-*.dist-info

最后,重新创建您的虚拟环境:

virtualenv <EXISTING_ENV_PATH>

这样一来,旧的Python核心文件和标准库(plus setuptoolspip)就被删除,而安装在其中的自定义库site-packages则在纯Python 中被保留并正常工作。二进制库可能需要也可能不需要重新安装才能正常运行。

这在安装了Django的5个虚拟环境中为我工作。

顺便说一句,如果./manage.py compilemessages之后仍然无法使用,请尝试以下操作:

brew install gettext && brew link gettext --force

Updated again: The following method might not work in newer versions of virtualenv. Before you try to make modifications to the old virtualenv, you should save the dependencies in a requirement file (pip freeze > requirements.txt) and make a backup of it somewhere else. If anything goes wrong, you can still create a new virtualenv and install the old dependencies in it (pip install -r requirements.txt).

Updated: I changed the answer 5 months after I originally answered. The following method is more convenient and robust.

Side effect: it also fixes the Symbol not found: _SSLv2_method exception when you do import ssl in a virtual environment after upgrading Python to v2.7.8.

Notice: Currently, this is for Python 2.7.x only.


If you’re using Homebrew Python on OS X, first deactivate all virtualenv, then upgrade Python:

brew update && brew upgrade python

Run the following commands (<EXISTING_ENV_PATH> is path of your virtual environment):

cd <EXISTING_ENV_PATH>
rm .Python
rm bin/pip{,2,2.7}
rm bin/python{,2,2.7}
rm -r include/python2.7
rm lib/python2.7/*
rm -r lib/python2.7/distutils
rm lib/python2.7/site-packages/easy_install.*
rm -r lib/python2.7/site-packages/pip
rm -r lib/python2.7/site-packages/pip-*.dist-info
rm -r lib/python2.7/site-packages/setuptools
rm -r lib/python2.7/site-packages/setuptools-*.dist-info

Finally, re-create your virtual environment:

virtualenv <EXISTING_ENV_PATH>

By doing so, old Python core files and standard libraries (plus setuptools and pip) are removed, while the custom libraries installed in site-packages are preserved and working, as soon as they are in pure Python. Binary libraries may or may not need to be reinstalled to function properly.

This worked for me on 5 virtual environments with Django installed.

BTW, if ./manage.py compilemessages is not working afterwards, try this:

brew install gettext && brew link gettext --force

回答 3

我无法在旧版本的基础上创建新的virtualenv。但是pip中有一些工具,可以更快地将需求重新安装到全新的venv中。Pip可以将requirements.txt中的每个项目构建到wheel包中,并将其存储在本地缓存中。当您创建新的venv并在其中运行pip install时,如果pip找到了它们,它将自动使用预建的轮子。车轮的安装速度比每个模块的setup.py运行速度快得多。

我的〜/ .pip / pip.conf看起来像这样:

[global]
download-cache = /Users/me/.pip/download-cache
find-links =
/Users/me/.pip/wheels/

[wheel]
wheel-dir = /Users/me/.pip/wheels

我安装了wheel(pip install wheel),然后运行pip wheel -r requirements.txt。这会将已构建的车轮存储在我的pip.conf中的wheel-dir中。

从那时起,每当我点安装这些要求中的任何一个时,它都会从轮子上安装它们,这非常快。

I wasn’t able to create a new virtualenv on top of the old one. But there are tools in pip which make it much faster to re-install requirements into a brand new venv. Pip can build each of the items in your requirements.txt into a wheel package, and store that in a local cache. When you create a new venv and run pip install in it, pip will automatically use the prebuilt wheels if it finds them. Wheels install much faster than running setup.py for each module.

My ~/.pip/pip.conf looks like this:

[global]
download-cache = /Users/me/.pip/download-cache
find-links =
/Users/me/.pip/wheels/

[wheel]
wheel-dir = /Users/me/.pip/wheels

I install wheel (pip install wheel), then run pip wheel -r requirements.txt. This stores the built wheels in the wheel-dir in my pip.conf.

From then on, any time I pip install any of these requirements, it installs them from the wheels, which is pretty quick.


回答 4

如何为现有的virtualenvwrapper项目升级Python版本并保持相同名称

我要为使用Doug Hellmann出色的virtualenvwrapper的任何人添加一个答案,特别是因为现有的答案对我没有帮助。

一些背景:

  • 我从事一些Python 2项目和Python 3项目;虽然我想使用python3 -m venv它,但它不支持Python 2环境
  • 当我开始一个新项目时,我使用mkproject它来创建虚拟环境,创建一个空项目目录,并在其中进行cds
  • 我想继续使用virtualenvwrapper的workon命令来激活任何项目,而与Python版本无关

方向:

假设您的现有项目已命名foo,并且当前正在运行Python 2(mkproject -p python2 foo),尽管从2.x升级到3.x,从3.6.0升级到3.6.1等的命令都是相同的。我还假设您当前位于激活的虚拟环境中。

1.停用并删除旧的虚拟环境:

$ deactivate
$ rmvirtualenv foo

请注意,如果您已将任何自定义命令添加到了挂钩(例如bin/postactivate),则需要在删除环境之前保存这些自定义命令。

2.将实际项目存储在temp目录中:

$ cd ..
$ mv foo foo-tmp

3.创建新的虚拟环境(和项目目录)并激活:

$ mkproject -p python3 foo

4.用实际项目替换生成的空项目目录,改回项目目录:

$ cd ..
$ mv -f foo-tmp foo
$ cdproject

5.重新安装依赖项,确认新的Python版本,等等:

$ pip install -r requirements.txt
$ python --version

如果这是一个常见的用例,我将考虑打开PR,为virtualenvwrapper 添加类似$ upgradevirtualenv/的内容$ upgradeproject

How to upgrade the Python version for an existing virtualenvwrapper project and keep the same name

I’m adding an answer for anyone using Doug Hellmann’s excellent virtualenvwrapper specifically since the existing answers didn’t do it for me.

Some context:

  • I work on some projects that are Python 2 and some that are Python 3; while I’d love to use python3 -m venv, it doesn’t support Python 2 environments
  • When I start a new project, I use mkproject which creates the virtual environment, creates an empty project directory, and cds into it
  • I want to continue using virtualenvwrapper’s workon command to activate any project irrespective of Python version

Directions:

Let’s say your existing project is named foo and is currently running Python 2 (mkproject -p python2 foo), though the commands are the same whether upgrading from 2.x to 3.x, 3.6.0 to 3.6.1, etc. I’m also assuming you’re currently inside the activated virtual environment.

1. Deactivate and remove the old virtual environment:

$ deactivate
$ rmvirtualenv foo

Note that if you’ve added any custom commands to the hooks (e.g., bin/postactivate) you’d need to save those before removing the environment.

2. Stash the real project in a temp directory:

$ cd ..
$ mv foo foo-tmp

3. Create the new virtual environment (and project dir) and activate:

$ mkproject -p python3 foo

4. Replace the empty generated project dir with real project, change back into project dir:

$ cd ..
$ mv -f foo-tmp foo
$ cdproject

5. Re-install dependencies, confirm new Python version, etc:

$ pip install -r requirements.txt
$ python --version

If this is a common use case, I’ll consider opening a PR to add something like $ upgradevirtualenv / $ upgradeproject to virtualenvwrapper.


回答 5

这种方法总是对我有用:

# First of all, delete all broken links. Replace  my_project_name` to your virtual env name
find ~/.virtualenvs/my_project_name/ -type l -delete
# Then create new links to the current Python version
virtualenv ~/.virtualenvs/my_project_name/
# It's it. Just repeat for each virtualenv located in ~/.virtualenvs

取自:

This approach always works for me:

# First of all, delete all broken links. Replace  my_project_name` to your virtual env name
find ~/.virtualenvs/my_project_name/ -type l -delete
# Then create new links to the current Python version
virtualenv ~/.virtualenvs/my_project_name/
# It's it. Just repeat for each virtualenv located in ~/.virtualenvs

Taken from:


回答 6

我将主目录从一台Mac移到了另一台(Mountain Lion到优胜美地),直到我失去了旧笔记本电脑的机会,才意识到虚拟机损坏了。brew自从Yosemite随附Python 2.7以来,我已经安装了指向Python 2.7的virtualenv点,因此我想将我的virtualenv更新为系统python。当我virtualenv在现有目录上运行时,OSError: [Errno 17] File exists: '/Users/hdara/bin/python2.7/lib/python2.7/config'出现错误。通过反复试验,我通过删除一些链接并手动修复了一些问题来解决此问题。这是我最终所做的(类似于@Rockalite所做的,但更简单):

cd <virtualenv-root>
rm lib/python2.7/config
rm lib/python2.7/lib-dynload
rm include/python2.7
rm .Python
cd lib/python2.7
gfind . -type l -xtype l | while read f; do ln -s -f /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/${f#./} $f; done

之后,我就可以在现有目录之上运行virtualenv了。

I moved my home directory from one mac to another (Mountain Lion to Yosemite) and didn’t realize about the broken virtualenv until I lost hold of the old laptop. I had the virtualenv point to Python 2.7 installed by brew and since Yosemite came with Python 2.7, I wanted to update my virtualenv to the system python. When I ran virtualenv on top of the existing directory, I was getting OSError: [Errno 17] File exists: '/Users/hdara/bin/python2.7/lib/python2.7/config' error. By trial and error, I worked around this issue by removing a few links and fixing up a few more manually. This is what I finally did (similar to what @Rockalite did, but simpler):

cd <virtualenv-root>
rm lib/python2.7/config
rm lib/python2.7/lib-dynload
rm include/python2.7
rm .Python
cd lib/python2.7
gfind . -type l -xtype l | while read f; do ln -s -f /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/${f#./} $f; done

After this, I was able to just run virtualenv on top of the existing directory.


回答 7

在使用Homebrew安装和升级Python3的OS X或macOS上,我必须先删除符号链接,然后python -m venv --upgrade ENV_DIR才能使用。

我将以下内容保存在upgrade_python3.sh中,所以我会记得从现在开始需要几个月的时间:

brew upgrade python3
find ~/.virtualenvs/ -type l -delete
find ~/.virtualenvs/ -type d -mindepth 1 -maxdepth 1 -exec python3 -m venv --upgrade "{}" \;

更新:虽然这乍看起来似乎很好,但是当我运行py.test时却出现了错误。最后,我只是从需求文件中重新创建了环境。

On OS X or macOS using Homebrew to install and upgrade Python3 I had to delete symbolic links before python -m venv --upgrade ENV_DIR would work.

I saved the following in upgrade_python3.sh so I would remember how months from now when I need to do it again:

brew upgrade python3
find ~/.virtualenvs/ -type l -delete
find ~/.virtualenvs/ -type d -mindepth 1 -maxdepth 1 -exec python3 -m venv --upgrade "{}" \;

UPDATE: while this seemed to work well at first, when I ran py.test it gave an error. In the end I just re-created the environment from a requirements file.


回答 8

如果您使用pipenv,我不知道是否可以在适当的位置升级环境,但是至少对于次要版本升级来说,它似乎足够聪明,在创建新环境时不从头开始重建软件包。例如,从3.6.4到3.6.5:

$ pipenv --python 3.6.5 install
Virtualenv already exists!
Removing existing virtualenv
Creating a v$ pipenv --python 3.6.5 install
Virtualenv already exists!
Removing existing virtualenv
Creating a virtualenv for this project
Using /usr/local/bin/python3.6m (3.6.5) to create virtualenv
Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/python3.6
Also creating executable in /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD
Installing dependencies from Pipfile.lock (84dd0e)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 47/47  00:00:24
To activate this project's virtualenv, run the following:
 $ pipenv shell
$ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
. /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/activate
bash-3.2$ . /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/activate
(autoscale-aBUhewiD) bash-3.2$ python
Python 3.6.5 (default, Mar 30 2018, 06:41:53) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>>

If you’re using pipenv, I don’t know if it’s possible to upgrade an environment in place, but at least for minor version upgrades it seems to be smart enough not to rebuild packages from scratch when it creates a new environment. E.g., from 3.6.4 to 3.6.5:

$ pipenv --python 3.6.5 install
Virtualenv already exists!
Removing existing virtualenv…
Creating a v$ pipenv --python 3.6.5 install
Virtualenv already exists!
Removing existing virtualenv…
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m (3.6.5) to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/python3.6
Also creating executable in /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD
Installing dependencies from Pipfile.lock (84dd0e)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 47/47 — 00:00:24
To activate this project's virtualenv, run the following:
 $ pipenv shell
$ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
. /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/activate
bash-3.2$ . /Users/dmoles/.local/share/virtualenvs/autoscale-aBUhewiD/bin/activate
(autoscale-aBUhewiD) bash-3.2$ python
Python 3.6.5 (default, Mar 30 2018, 06:41:53) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>>

回答 9

我只想澄清一下,因为有些答案是指venv,有些则是指virtualenv

在上支持使用-p--python标志virtualenv,但不支持venv。如果您有多个Python版本,并且想要指定使用哪个版本创建venv,请在命令行上执行以下操作:

malikarumi@Tetuoan2:~/Projects$ python3.6 -m venv {path to pre-existing dir you want venv in}

当然,您也可以venv像其他人指出的那样进行升级,但是前提是您已经升级了最初用于创建该Python的Python venv。您无法升级到系统上某个地方尚未拥有的Python版本,因此请确保首先获取所需的版本,然后再从中获取所需的所有Venv。

I just want to clarify, because some of the answers refer to venv and others refer to virtualenv.

Use of the -p or --python flag is supported on virtualenv, but not on venv. If you have more than one Python version and you want to specify which one to create the venv with, do it on the command line, like this:

malikarumi@Tetuoan2:~/Projects$ python3.6 -m venv {path to pre-existing dir you want venv in}

You can of course upgrade with venv as others have pointed out, but that assumes you have already upgraded the Python that was used to create that venv in the first place. You can’t upgrade to a Python version you don’t already have on your system somewhere, so make sure to get the version you want, first, then make all the venvs you want from it.


回答 10

步骤1:冻结要求并备份现有环境

pip freeze > requirements.txt
deactivate
mv env env_old

步骤2:安装Python 3.7并激活虚拟环境

sudo apt-get install python3.7-venv
python3.7 -m venv env
source env/bin/activate
python --version

步骤3:安装需求

sudo apt-get install python3.7-dev
pip3 install -r requirements.txt

Step 1: Freeze requirement & take a back-up of existing env

pip freeze > requirements.txt
deactivate
mv env env_old

Step 2: Install Python 3.7 & activate virutal environment

sudo apt-get install python3.7-venv
python3.7 -m venv env
source env/bin/activate
python --version

Step 3: Install requirements

sudo apt-get install python3.7-dev
pip3 install -r requirements.txt

回答 11

对于有问题的每个人

错误:命令'[‘/ Users / me / Sites / site / venv3 / bin / python3’,’-Im’,’ensurepip’,’-upgrade’,’-default-pip’]’返回非零退出状态1。

您必须安装python3.6-venv

 sudo apt-get install python3.6-venv

For everyone with the problem

Error: Command ‘[‘/Users/me/Sites/site/venv3/bin/python3’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]’ returned non-zero exit status 1.

You have to install python3.6-venv

 sudo apt-get install python3.6-venv

Python pip安装失败:无效的命令egg_info

问题:Python pip安装失败:无效的命令egg_info

我最近经常尝试使用pip安装Python软件包时发现这一点收到以下错误。

我在网上找到了一个参考,该参考必须从下载目录中使用“ python2 setup.py install ”,并且确实发现,如果我手动找到并下载了该软件包(从pypi),它将可以正常工作。

但是,我不知道pip将软件包下载到何处,和/或为什么这种方式会失败。

我尝试进行pip升级,但是它也以类似的方式失败,出现了一系列“未知分发选项”错误(entry_points,zip_safe,test_suite,tests_require)!

尝试使用ActiveState的pypm失败,因为它们的库基较小,并且不包含这些软件包。

C:\test>pip install requests-oauth
Downloading/unpacking requests-oauth
  Downloading requests-oauth-0.4.1.tar.gz
  Running setup.py egg_info for package requests-oauth
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
      warnings.warn(msg)
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
      warnings.warn(msg)
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'
    Complete output from command python setup.py egg_info:
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
  warnings.warn(msg)

E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)

usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: -c --help [cmd1 cmd2 ...]
   or: -c --help-commands
   or: -c cmd --help

error: invalid command 'egg_info'

I find that recently often when I try to install a Python package using pip, I get the error(s) below.

I found a reference online that one has to use “python2 setup.py install” from the download directory, and indeed find that this will then work if I manually find and download the package (from pypi).

But, I don’t know where pip is downloading packages to, and/or why it is failing in this manner.

I tried to do a pip upgrade, but it also failed in a similar manner, with a bunch of “Unknown distribution option” errors (entry_points, zip_safe, test_suite, tests_require)!

Trying to use ActiveState’s pypm fails, because they have a smaller library base, and it doesn’t include these packages.

C:\test>pip install requests-oauth
Downloading/unpacking requests-oauth
  Downloading requests-oauth-0.4.1.tar.gz
  Running setup.py egg_info for package requests-oauth
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
      warnings.warn(msg)
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
      warnings.warn(msg)
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'
    Complete output from command python setup.py egg_info:
    E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
  warnings.warn(msg)

E:\Plang\ActivePython\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)

usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: -c --help [cmd1 cmd2 ...]
   or: -c --help-commands
   or: -c cmd --help

error: invalid command 'egg_info'

回答 0

安装分发附带的egg_info

应该很简单pip install Distribute

从0.7版开始,Distribute已合并到Setuptools中。如果您使用的版本<= 0.6,请使用pip install --upgrade setuptools或进行升级easy_install -U setuptools

Install distribute, which comes with egg_info.

Should be as simple as pip install Distribute.

Distribute has been merged into Setuptools as of version 0.7. If you are using a version <=0.6, upgrade using pip install --upgrade setuptools or easy_install -U setuptools.


回答 1

由于分发已经合并回到setuptools中,现在建议改为安装/升级setuptools:

[sudo] pip install --upgrade setuptools

As distribute has been merged back into setuptools, it is now recommended to install/upgrade setuptools instead:

[sudo] pip install --upgrade setuptools

回答 2

请记住,pip install --upgrade Distribute如果您已经安装了它,pip可能必须pip2做,并且在某些系统上(它是我的)可能需要使用Python2。

Bear in mind you may have to do pip install --upgrade Distribute if you have it installed already and your pip may be called pip2 for Python2 on some systems (it is on mine).


回答 3

我遇到了这个问题,以及OS X v10.9(Mavericks)上Brewed Python的其他问题。

sudo pip install --upgrade setuptools

不适用于我,我认为我的setuptools / distribute安装程序很烂。

我终于通过运行使它起作用

sudo easy_install -U setuptools

I had this issue, as well as some other issues with Brewed Python on OS X v10.9 (Mavericks).

sudo pip install --upgrade setuptools

didn’t work for me, and I think my setuptools/distribute setup was botched.

I finally got it to work by running

sudo easy_install -U setuptools

回答 4

上面的这些都不适合我在Ubuntu 12.04 LTS(精确的穿山甲)上使用,下面是我最终解决的方法:

下载ez_setup.py下载setuptools的(请参阅“安装说明”部分),则:

$ sudo python ez_setup.py

我希望它可以节省一些时间。

None of the above worked for me on Ubuntu 12.04 LTS (Precise Pangolin), and here’s how I fixed it in the end:

Download ez_setup.py from download setuptools (see “Installation Instructions” section) then:

$ sudo python ez_setup.py

I hope it saves someone some time.


回答 5

当您尝试安装时,可能会发生此错误pycurl

在这种情况下,您应该

sudo apt-get install libcurl4-gnutls-dev librtmp-dev

(在这里找到:https : //gist.github.com/lxneng/1031014

This error can occur when you trying to install pycurl.

In this case you should do

sudo apt-get install libcurl4-gnutls-dev librtmp-dev

(founded here: https://gist.github.com/lxneng/1031014 )


回答 6

在CentOS 6.5上,全新安装的简短回答是:

yum -y install python-pip pip install -U pip pip install -U setuptools pip install -U setuptools

您不会看到两倍,必须运行两次setuptools升级。长答案如下:

python-pip使用yum 安装软件包会带来python-setuptools依赖性。这是一个很旧的版本,因此实际上是在安装distribute (0.6.10)。安装软件包管理器后,我们通常要对其进行更新,因此我们pip install -U pip。对我来说,当前的pip版本是1.5.6。

现在我们去更新setuptools,这个pip版本很聪明,知道它应该先删除旧版本的distribution。它会执行此操作,但是会安装而不是安装最新版本的setuptools setuptools (0.6c11)

此时,由于setuptools的版本太旧,各种情况都被破坏了,但实际上我们已经到了一半。如果现在第二次运行完全相同的命令pip install -U setuptools,则将删除旧版本的setuptools,并安装5.5.1版。我不知道为什么pip不能一口气将我们带到新版本,但这是正在发生的事情,希望它将帮助其他人看到这一点并知道您不会发疯。

On CentOS 6.5, the short answer from a clean install is:

yum -y install python-pip pip install -U pip pip install -U setuptools pip install -U setuptools

You are not seeing double, you must run the setuptools upgrade twice. The long answer is below:

Installing the python-pip package using yum brings python-setuptools along as a dependency. It’s a pretty old version and hence it’s actually installing distribute (0.6.10). After installing a package manager we generally want to update it, so we do pip install -U pip. Current version of pip for me is 1.5.6.

Now we go to update setuptools and this version of pip is smart enough to know it should remove the old version of distribute first. It does this, but then instead of installing the latest version of setuptools it installs setuptools (0.6c11).

At this point all kinds of things are broken due to this extremely old version of setuptools, but we’re actually halfway there. If we now run the exact same command a second time, pip install -U setuptools, the old version of setuptools is removed, and version 5.5.1 is installed. I don’t know why pip doesn’t take us straight to the new version in one shot, but this is what’s happening and hopefully it will help others to see this and know you’re not going crazy.


回答 7

看起来默认的easy_install在其当前位置已损坏:

$ which easy_install /usr/bin/easy_install

解决此问题的一种方法是在站点包中使用easy_install。例如:

$ sudo python /Library/Python/2.7/site-packages/easy_install.py boto

Looks like the default easy_install is broken in its current location:

$ which easy_install /usr/bin/easy_install

A way to overcome this is to use the easy_install in site packages. For example:

$ sudo python /Library/Python/2.7/site-packages/easy_install.py boto


回答 8

我遇到了同样的问题,并且尝试了以上所有答案。但不幸的是,以上方法均无效。

作为说明,我终于通过解决了这个问题pip uninstall distribute

I was facing the same issue and I tried all the above answers. But unfortunately, none of the above worked.

As a note, I finally solve this by pip uninstall distribute.


回答 9

我知道这是一个较旧的问题,但这是我用来cassandra-driver实际安装在Windows 7 / Python2上的步骤。我家里有Windows 10 / Python3,今晚将在这里进行测试。我已经确认这也可以在Windows 10上同时使用Python 2和3。

问题

Command "python setup.py egg_info" failed with error code 1 in c:\users\Frito\appdata\local\temp\pip-build-7dgmdc\cassandra-driver

TL; DR解决方案

(我希望有人解释为什么这样做)

  • 尝试pip install cassandra-driver并收到上述错误消息
  • 尝试pip install --pre cassandra-driver并出现以下错误
distutils.errors.DistutilsError: Setup script exited with error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27

Command "c:\users\Frito\.virtualenvs\symdash\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\Frito\\appdata\\local\\temp\\pip-build-sesxxu\\cassandra-driver\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record  c:\users\Frito\appdata\local\temp\pip-ujsxsk-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\Frito\.virtualenvs\symdash\include\site\python2.7\cassandra-driver"  failed with error code 1 in  c:\users\Frito\appdata\local\temp\pip-build-sesxxu\cassandra-driver
  • 已安装 Microsoft Visual C++ Compiler for Python 2.7
  • 成功执行 pip install --pre cassandra-driver
  • 成功执行 pip uninstall cassandra-driver
  • 成功执行 pip install cassandra-driver

重申一下,我不太确定为什么这样做。现在我的两个主要结论是,不管是C ++编译器是必需的或者是运行--pre在第一时间安装一些依赖人失踪,从选项“正规军”安装。当我有更多详细信息时,我将在今晚下班后更新。

I know this is an older question but here are the steps I used to get cassandra-driver to actually install on Windows 7 / Python2. I have windows 10 / Python3 at home where I will test this tonight. I have confirmed this also works on Windows 10 with both Python 2 and 3.

Problem

Command "python setup.py egg_info" failed with error code 1 in c:\users\Frito\appdata\local\temp\pip-build-7dgmdc\cassandra-driver

TL;DR Solution

Solution (I’d love for someone to explain why this worked)

  • Attempted pip install cassandra-driver and got the above error message
  • Attempted pip install --pre cassandra-driver and got the following error
distutils.errors.DistutilsError: Setup script exited with error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27

Command "c:\users\Frito\.virtualenvs\symdash\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\Frito\\appdata\\local\\temp\\pip-build-sesxxu\\cassandra-driver\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record  c:\users\Frito\appdata\local\temp\pip-ujsxsk-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\Frito\.virtualenvs\symdash\include\site\python2.7\cassandra-driver"  failed with error code 1 in  c:\users\Frito\appdata\local\temp\pip-build-sesxxu\cassandra-driver
  • Installed Microsoft Visual C++ Compiler for Python 2.7
  • Successfully executed pip install --pre cassandra-driver
  • Successfully executed pip uninstall cassandra-driver
  • Successfully executed pip install cassandra-driver

To reiterate, I’m not really sure why this worked. Right now my two leading conclusions are that either the C++ compiler is required or that running the --pre option the first time installed some dependencies that were missing from the ‘regular’ install. I’ll update tonight after work when I have more details.


回答 10

pip install -U setuptools并且easy_install将egg-info放在错误的目录中。

然后我就重新安装了apt-get install python-dev。然后让我安装想要的驱动程序

pip install -U setuptools and easy_install was putting egg-info in the wrong directory.

Then I just reinstalled apt-get install python-dev. Let me install the drivers I want after that


回答 11

尝试以下命令:

pip install setuptools==28.8.0

try the following command:

pip install setuptools==28.8.0

回答 12

我只是将liquidki的答案转换为Ubuntu命令。在基于Ubuntu的系统上,它可以工作!:

sudo apt -y install python-pip
pip install -U pip
sudo pip install -U setuptools

I just convert liquidki’s answer into Ubuntu commands. On an Ubuntu based system it works!:

sudo apt -y install python-pip
pip install -U pip
sudo pip install -U setuptools

回答 13

对我来说,将点数从8.1.1升级到9.0.1解决了此问题。

您可以运行类似sudo -H pip2 install --upgrade pip升级pip版本的操作。

For me upgrading pip from 8.1.1 to 9.0.1 solved this problem.

You can run something like sudo -H pip2 install --upgrade pip to upgrade your pip version.


回答 14

当我想在虚拟环境中使用命令安装cairosvg时,我也遇到类似的错误消息“命令’python setup.py egg_info’失败,错误代码为1” pip install cairosvg

然后,我曾经尝试都pip install --upgrade pippip install --upgrade setuptools运行前pip3 install cairosvg,但我仍然得到这个错误。

我可以摆脱这个错误与须藤在安装命令前:sudo pip install cairosvg。但请注意,带有sudo的命令将为系统python而非虚拟环境安装软件包。

因此,我进一步检查了错误消息,并发现在安装cairocffi时收到错误消息。然后安装特定版本的cairocffi(请参阅此答案在安装cairosvg之前,先安装)。这就是我解决问题的方式。

I also meet a similar error message “Command ‘python setup.py egg_info’ failed with error code 1” when I want to install cairosvg with command pip install cairosvg in a virtual environment.

Then I have tried both pip install --upgrade pip and pip install --upgrade setuptools before running pip3 install cairosvg, but I still get this error.

I can get rid of this error with sudo in front of the installation command : sudo pip install cairosvg. But note that the command with sudo will install the package for the system python rather than the virtual environment.

So, I further check the error message and find that I get the error while installing the cairocffi. Then I install a certain version of cairocffi (refer to this answer) before install cairosvg. That is how I solve my problem.


pip等同于`npm install package –save-dev`吗?

问题:pip等同于`npm install package –save-dev`吗?

在nodejs中,我可以npm install package --save-dev将已安装的软件包保存到软件包中。

如何在Python包管理器中实现同一目的pip?我想将软件包名称及其版本保存到,例如,requirements.pip使用来安装软件包之后pip install package --save-dev requirements.pip

In nodejs, I can do npm install package --save-dev to save the installed package into the package.

How do I achieve the same thing in Python package manager pip? I would like to save the package name and its version into, say, requirements.pip just after installing the package using something like pip install package --save-dev requirements.pip.


回答 0

没有与的等效项pip

最好的方法是 pip install package && pip freeze > requirements.txt

您可以在其文档页面上看到所有可用的选项。

如果确实让您感到困扰,那么编写一个自定义bash脚本(pips)会很困难,该脚本带有一个-s参数并requirements.txt自动冻结到您的文件中。

编辑1

自编写此书以来,提供--save-dev类似于NPM 的自动选项没有任何变化,但是Kenneth Reitz(requests及更多作者)发布了一些有关更好的点子工作流程以更好地处理pip更新的信息。

编辑2

从上面的“更好的点子工作流程”文章链接到现在,建议将其用于pipenv管理需求和虚拟环境。最近使用了很多,我想总结一下转换是多么简单:

安装pipenv(在Mac上)

brew install pipenv

pipenv创建并管理它自己的虚拟环境,因此在具有现有的项目中requirements.txt,安装所有要求(我使用Python3.7,但--three如果不这样做,则可以删除)就很简单:

pipenv --three install

激活virtualenv以运行命令也很容易

pipenv shell

安装要求将自动更新PipfilePipfile.lock

pipenv install <package>

还可以更新过期的软件包

pipenv update

我强烈建议您进行检查,尤其是来自npm背景时,因为它的感觉package.jsonpackage-lock.json

There isn’t an equivalent with pip.

Best way is to pip install package && pip freeze > requirements.txt

You can see all the available options on their documentation page.

If it really bothers you, it wouldn’t be too difficult to write a custom bash script (pips) that takes a -s argument and freezes to your requirements.txt file automatically.

Edit 1

Since writing this there has been no change in providing an auto --save-dev option similar to NPM however Kenneth Reitz (author of requests and many more) has released some more info about a better pip workflow to better handle pip updates.

Edit 2

Linked from the “better pip workflow” article above it is now recommended to use pipenv to manage requirements and virtual environments. Having used this a lot recently I would like to summarise how simple the transition is:

Install pipenv (on Mac)

brew install pipenv

pipenv creates and manages it’s own virtual environments so in a project with an existing requirements.txt, installing all requirements (I use Python3.7 but you can remove the --three if you do not) is as simple as:

pipenv --three install

Activating the virtualenv to run commands is also easy

pipenv shell

Installing requirements will automatically update the Pipfile and Pipfile.lock

pipenv install <package>

It’s also possible to update out-of-date packages

pipenv update

I highly recommend checking it out especially if coming from a npm background as it has a similar feel to package.json and package-lock.json


回答 1

这条简单的线是一个起点。您可以轻松构建一个bash命令来重用该行中的PACKAGE。

pip install PACKAGE && pip freeze | grep PACKAGE >> requirements.txt

感谢@devsnd提供了简单的bash函数示例:

function pip-install-save { 
    pip install $1 && pip freeze | grep $1 >> requirements.txt
}

要使用它,只需运行:

pip-install-save some-package

This simple line is a starting point. You can easily built a bash command to reuse the PACKAGE in the line.

pip install PACKAGE && pip freeze | grep PACKAGE >> requirements.txt

Thanks to @devsnd for the simple bash function example:

function pip-install-save { 
    pip install $1 && pip freeze | grep $1 >> requirements.txt
}

To use it, just run:

pip-install-save some-package

回答 2

我创建Python包,各地的实际包装pip称为PIPM。所有pip命令将按原样运行,并且它们将反映在需求文件中。与pip-save(我发现但无法使用的类似工具)不同,它可以处理许多文件和环境(测试,开发,生产等)。它还具有用于升级所有/任何依赖项的命令。

安装

pipm install pkg-name

安装为开发依赖项

pipm install pkg-name --dev

安装为测试依赖项

pipm install pkg-name --test

清除

pipm uninstall pkg-name

更新所有依赖

pipm update

从需求文件安装所有依赖项

pipm install

包括开发依赖

pipm install --dev

I’ve created python package that wraps around the actual pip called pipm. All pip commands will work as it is, plus they will be reflected in the requirements file. Unlike pip-save(similar tool I found and wasn’t able to use) it can handle many files and environments(test, dev, production, etc. ). It also has command to upgrade all/any of your dependencies.

installation

pipm install pkg-name

installation as development dependency

pipm install pkg-name --dev

installation as testing dependency

pipm install pkg-name --test

removal

pipm uninstall pkg-name

update all your dependencies

pipm update

install all your dependencies from the requirements file

pipm install

including development dependencies

pipm install --dev


回答 3

更新:显然,pipenv没有得到Python维护者的正式认可,并且以前链接的页面是由另一个组织拥有的。该工具各有利弊,但以下解决方案仍然可以达到OP所寻求的结果。

pipenv是一个依赖项管理工具,它包装pip并提供您所要求的内容:

https://pipenv.kennethreitz.org/en/latest/#example-pipenv-workflow

$ pipenv install <package>

如果不存在,这将创建一个Pipfile。如果存在,它将使用您提供的新软件包自动进行编辑。

A Pipfile直接等于package.json,而Pipfile.lock对应于package-lock.json

Update: apparently, pipenv is not officially endorsed by Python maintainers, and the previously-linked page is owned by a different organization. The tool has its pros and cons, but the below solution still achieves the result that the OP is seeking.

pipenv is a dependency management tool that wraps pip and, among other things, provides what you’re asking:

https://pipenv.kennethreitz.org/en/latest/#example-pipenv-workflow

$ pipenv install <package>

This will create a Pipfile if one doesn’t exist. If one does exist, it will automatically be edited with the new package your provided.

A Pipfile is a direct equivalent of package.json, while Pipfile.lock corresponds to package-lock.json.


回答 4

我快速pip添加--save了安装/卸载命令选项。

请查看我的博客以获取有关此黑客的更多信息:http : //blog.abhiomkar.in/2015/11/12/pip-save-npm-like-behaviour-to-pip/

安装(GitHub):https : //github.com/abhiomkar/pip-save

希望这可以帮助。

I made a quick hack on pip to add --save option to install/uninstall commands.

Please have a look at my blog for more information about this hack: http://blog.abhiomkar.in/2015/11/12/pip-save-npm-like-behaviour-to-pip/

Installation (GitHub): https://github.com/abhiomkar/pip-save

Hope this helps.


回答 5

您可以将其手动保存在Makefile(或文本文件中,然后导入到Makefile中):


PYTHON=.venv/bin/python # path to pyphon
PIP=.venv/bin/pip # path to pip
SOURCE_VENV=. .venv/bin/activate


install:
    virtualenv .venv
    $(SOURCE_VENV) && $(PIP) install -e PACKAGE
    $(SOURCE_VENV) && $(PIP) install -r requirements.txt # other required packages

然后运行 make install

you can manually save it in a Makefile (or a text file and then imported in your Makefile):


PYTHON=.venv/bin/python # path to pyphon
PIP=.venv/bin/pip # path to pip
SOURCE_VENV=. .venv/bin/activate


install:
    virtualenv .venv
    $(SOURCE_VENV) && $(PIP) install -e PACKAGE
    $(SOURCE_VENV) && $(PIP) install -r requirements.txt # other required packages

and then just run make install


回答 6

我正在使用此小命令行来安装软件包并将其版本保存在requirements.txtpkg=package && pip install $pkg && echo $(pip freeze | grep -i $pkg) >> requirements.txt

I am using this small command line to install a package and save its version in requirements.txt : pkg=package && pip install $pkg && echo $(pip freeze | grep -i $pkg) >> requirements.txt


回答 7

使shell函数执行此操作怎么样?将以下代码添加到您的~/.profile~/.bashrc

pips() {
    local pkg=$1

    if [ -z "$1" ]; then
        echo "usage: pips <pkg name>"
        return 1
    fi

    local _ins="pip install $pkg"
    eval $_ins
    pip freeze | grep $pkg -i >> requirements.txt
}

然后运行source ~/.profilesource ~/.bashrc将其导入到当前终端

例如,当您要安装&&保存软件包时,只需运行即可pips requests。安装软件包后,其版本将保存到requirements.txt您的当前目录中。

How about make a shell function to do this ? Add below code to your ~/.profile or ~/.bashrc

pips() {
    local pkg=$1

    if [ -z "$1" ]; then
        echo "usage: pips <pkg name>"
        return 1
    fi

    local _ins="pip install $pkg"
    eval $_ins
    pip freeze | grep $pkg -i >> requirements.txt
}

then run source ~/.profile or source ~/.bashrc to import it to your current terminal

when you want to install && save a package, just run, for example pips requests. after package was installed, its version will be save into requirements.txt in your current directory.


如何在Python 3.x和Python 2.x上使用pip

问题:如何在Python 3.x和Python 2.x上使用pip

我安装了Python 3.x(在Ubuntu上除了Python 2.x之外),然后慢慢开始配对在Python 2.x中使用的模块。

所以我想知道,应该为Python 2.x和Python 3.x使用pip来简化生活吗?

I installed Python 3.x (besides Python 2.x on Ubuntu) and slowly started to pair modules I use in Python 2.x.

So I wonder, what approach should I take to make my life easy by using pip for both Python 2.x and Python 3.x?


回答 0

您应该采取的方法是安装 pip为Python 3.2。

您可以通过以下方式执行此操作:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.2 get-pip.py

然后,您可以使用来安装适用于Python 3.2的内容pip-3.2,并使用来安装适用于Python 2-7的内容pip-2.7。该pip命令最终将指向其中之一,但是我不确定是哪一个,因此您必须进行检查。

The approach you should take is to install pip for Python 3.2.

You do this in the following way:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.2 get-pip.py

Then, you can install things for Python 3.2 with pip-3.2, and install things for Python 2-7 with pip-2.7. The pip command will end up pointing to one of these, but I’m not sure which, so you will have to check.


回答 1

您还可以做的是使用apt-get:

apt-get install python3-pip

以我的经验,这也很流利,而且您会从apt-get中获得所有好处。

What you can also do is to use apt-get:

apt-get install python3-pip

In my experience this works pretty fluent too, plus you get all the benefits from apt-get.


回答 2

首先,使用以下命令安装Python 3 pip:

sudo apt-get install python3-pip

然后,Python 3 pip使用:

pip3 install <module-name>

对于Python 2 pip使用:

pip install <module-name>

First, install Python 3 pip using:

sudo apt-get install python3-pip

Then, to use Python 3 pip use:

pip3 install <module-name>

For Python 2 pip use:

pip install <module-name>

回答 3

如果您不想每次使用pip时都指定版本:

安装点子:

$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

并导出路径:

$ export PATH=/Library/Frameworks/Python.framework/Versions/<version number>/bin:$PATH

If you don’t want to have to specify the version every time you use pip:

Install pip:

$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

and export the path:

$ export PATH=/Library/Frameworks/Python.framework/Versions/<version number>/bin:$PATH

回答 4

最短的方法:

python3 -m pip install package
python -m pip install package

The shortest way:

python3 -m pip install package
python -m pip install package

回答 5

这在OS X上对我有用:(我之所以这样说,是因为有时Mac对于每个开放源代码工具都拥有“自己的”版本,这是一种痛苦,并且您无法删除它,因为“其改进”使它对于其他苹果产品来说都是独一无二的,如果您将其删除,事情就会开始恶化)

我按照@Lennart Regebro提供的步骤来获取python 3的pip,但是python 2的pip仍然是第一个出现的路径,所以…我要做的是在/ usr / bin内创建指向python 3的符号链接(实际上,我也做了同样的事情来让我的2条python和平运行):

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/pip /usr/bin/pip3

请注意,我3在末尾添加了一个,因此基本上您要做的是使用pip3而不是pip

该帖子很旧,但我希望有一天能对某人有所帮助。从理论上讲,这应该适用于任何LINUX系统。

This worked for me on OS X: (I say this because sometimes is a pain that mac has “its own” version of every open source tool, and you cannot remove it because “its improvements” make it unique for other apple stuff to work, and if you remove it things start falling appart)

I followed the steps provided by @Lennart Regebro to get pip for python 3, nevertheless pip for python 2 was still first on the path, so… what I did is to create a symbolic link to python 3 inside /usr/bin (in deed I did the same to have my 2 pythons running in peace):

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/pip /usr/bin/pip3

Notice that I added a 3 at the end, so basically what you have to do is to use pip3 instead of just pip.

The post is old but I hope this helps someone someday. this should theoretically work for any LINUX system.


回答 6

在Suse Linux 13.2上,pip调用python3,但是pip2可用于使用旧版本的python。

On Suse Linux 13.2, pip calls python3, but pip2 is available to use the older python version.


回答 7

在Windows中,先安装Python 3.7,然后再安装Python 2.7。然后,使用命令提示符:

pip安装python2-module-name

pip3安装python3-module-name

就这样

In Windows, first installed Python 3.7 and then Python 2.7. Then, use command prompt:

pip install python2-module-name

pip3 install python3-module-name

That’s all


回答 8

请注意,在msys2上,我发现以下命令会有所帮助:

$ pacman -S python3-pip
$ pip3 install --upgrade pip
$ pip3 install --user package_name

Please note that on msys2 I’ve found these commands to be helpful:

$ pacman -S python3-pip
$ pip3 install --upgrade pip
$ pip3 install --user package_name

回答 9

以为这是个老问题,我想我有更好的解决方案

  1. 要将pip用于python 2.x环境,请使用以下命令-

    py -2 -m pip安装-r requirements.txt

  2. 要将pip用于python 3.x环境,请使用以下命令-

    py -3 -m pip install -r requirements.txt

Thought this is old question, I think I have better solution

  1. To use pip for a python 2.x environment, use this command –

    py -2 -m pip install -r requirements.txt

  2. To use pip for python 3.x environment, use this command –

    py -3 -m pip install -r requirements.txt


为什么我不能在python中创建轮子?

问题:为什么我不能在python中创建轮子?

这是我正在运行的命令:

$ python setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'

$ pip --version
pip 1.5.6 from /usr/local/lib/python3.4/site-packages (python 3.4)

$ python -c "import setuptools; print(setuptools.__version__)"
2.1

$ python --version
Python 3.4.1

$ which python
/usr/local/bin/python

此外,我正在使用自制的python运行Mac

这是我的setup.py脚本:https : //gist.github.com/cloudformdesign/4791c46fe7cd52eb61cd

我快要疯了-我不知道为什么这不起作用。

Here are the commands I am running:

$ python setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'

$ pip --version
pip 1.5.6 from /usr/local/lib/python3.4/site-packages (python 3.4)

$ python -c "import setuptools; print(setuptools.__version__)"
2.1

$ python --version
Python 3.4.1

$ which python
/usr/local/bin/python

Also, I am running a mac with homebrewed python

Here is my setup.py script: https://gist.github.com/cloudformdesign/4791c46fe7cd52eb61cd

I’m going absolutely crazy — I can’t figure out why this wouldn’t be working.


回答 0

首先安装wheel软件包

pip install wheel

文档并不太清楚,但是“ wheel项目为setuptools提供了bdist_wheel命令”实际上是指“ wheel package …”

Install the wheel package first:

pip install wheel

The documentation isn’t overly clear on this, but “the wheel project provides a bdist_wheel command for setuptools” actually means “the wheel package…”.


回答 1

我也遇到了错误信息 invalid command 'bdist_wheel'

原来包setup.py使用的是distutils而不是setuptools。如下进行更改可以使我制造轮子。

#from distutils.core import setup
from setuptools import setup

I also ran into the error message invalid command 'bdist_wheel'

It turns out the package setup.py used distutils rather than setuptools. Changing it as follows enabled me to build the wheel.

#from distutils.core import setup
from setuptools import setup

回答 2

也更新您的setuptools。

pip install setuptools --upgrade

如果仍然失败,则可以尝试使用其他--force标志。

Update your setuptools, too.

pip install setuptools --upgrade

If that fails too, you could try with additional --force flag.


回答 3

在以前无法正常工作之后,我也突然遇到了这种情况,这是因为我在virtualenv中,wheel没有安装在virtualenv中。

I also ran into this all of a sudden, after it had previously worked, and it was because I was inside a virtualenv, and wheel wasn’t installed in the virtualenv.


回答 4

更新您的pip第一个:

pip install --upgrade pip

对于Python 3:

pip3 install --upgrade pip

Update your pip first:

pip install --upgrade pip

for Python 3:

pip3 install --upgrade pip

回答 5

也可能是您只有python3系统。因此,您已经通过pip3 install安装了必要的软件包,例如pip3 install wheel

您需要专门使用python3构建自己的东西。

python3 setup.py sdist
python3 setup.py bdist_wheel

干杯。

It could also be that you have a python3 system only. You therefore have installed the necessary packages via pip3 install , like pip3 install wheel.

You’ll need to build your stuff using python3 specifically.

python3 setup.py sdist
python3 setup.py bdist_wheel

Cheers.


回答 6

提出另一个答案:尝试检查您的PYTHONPATH

首先,尝试重新安装wheel

pip install wheel

这应该告诉您车轮安装在哪里,例如:

Requirement already satisfied: wheel in /usr/local/lib/python3.5/dist-packages

然后将wheel的位置添加到您的PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.5/dist-packages/wheel

现在,构建轮子应该可以正常工作。

python setup.py bdist_wheel

Throwing in another answer: Try checking your PYTHONPATH.

First, try to install wheel again:

pip install wheel

This should tell you where wheel is installed, eg:

Requirement already satisfied: wheel in /usr/local/lib/python3.5/dist-packages

Then add the location of wheel to your PYTHONPATH:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.5/dist-packages/wheel

Now building a wheel should work fine.

python setup.py bdist_wheel

回答 7

我尝试了这里所说的一切,没有任何运气,但找到了解决方法。运行此命令后(失败):bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

转到工具制作的临时目录(在最后一个命令的输出中给出),然后执行python setup.py bdist_wheel。该.whl文件位于dist文件夹中。

I tried everything said here without any luck, but found a workaround. After running this command (and failing) : bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Go to the temporary directory the tool made (given in the output of the last command), then execute python setup.py bdist_wheel. The .whl file is in the dist folder.


“ pip install –user…”的目的是什么?

问题:“ pip install –user…”的目的是什么?

来自pip install --help

 --user      Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on
             Windows. (See the Python documentation for site.USER_BASE for full details.)

site.USER_BASE的文档是一个令人困扰的有趣的* NIX主题,我不明白。

--user普通英语的目的是什么?为什么安装软件包很~/.local/重要?为什么不将可执行文件放在$ PATH中?

From pip install --help:

 --user      Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on
             Windows. (See the Python documentation for site.USER_BASE for full details.)

The documentation for site.USER_BASE is a terrifying wormhole of interesting *NIX subject matter that I don’t understand.

What is the purpose of --user in plain english? Why would intalling the package to ~/.local/ matter? Why not just put an executable somewhere in my $PATH?


回答 0

pip默认将Python软件包安装到系统目录(例如/usr/local/lib/python3.4)。这需要root访问。

--user 而是在您的主目录中进行pip安装软件包,该软件包不需要任何特殊特权。

pip defaults to installing Python packages to a system directory (such as /usr/local/lib/python3.4). This requires root access.

--user makes pip install packages in your home directory instead, which doesn’t require any special privileges.


回答 1

--user安装在中site.USER_SITE

就我而言,是/Users/.../Library/Python/2.7/bin。因此,我已将其添加到我的PATH(~/.bash_profile文件中):

export PATH=$PATH:/Users/.../Library/Python/2.7/bin

--user installs in site.USER_SITE.

For my case, it was /Users/.../Library/Python/2.7/bin. So I have added that to my PATH (in ~/.bash_profile file):

export PATH=$PATH:/Users/.../Library/Python/2.7/bin

回答 2

其他答案提到site.USER_SITE放置Python包的位置。如果您要查找二进制文件,请输入{site.USER_BASE}/bin

如果要将此目录添加到外壳程序的搜索路径中,请使用:

export PATH="${PATH}:$(python3 -c 'import site; print(site.USER_BASE)')/bin"

Other answers mention site.USER_SITE as where Python packages get placed. If you’re looking for binaries, these go in {site.USER_BASE}/bin.

If you want to add this directory to your shell’s search path, use:

export PATH="${PATH}:$(python3 -c 'import site; print(site.USER_BASE)')/bin"

回答 3

只是警告:

根据此问题--user当前在虚拟环境中无效pip,因为用户位置对于虚拟环境而言实际上没有任何意义。

因此,请勿pip install --user some_pkg 在虚拟环境内使用,否则,虚拟环境pip会被混淆。有关更多详细信息,请参见此答案

Just a warning:

According to this issue, --user is currently not valid inside a virtual env’s pip, since a user location doesn’t really make sense for a virtual environment.

So do not use pip install --user some_pkg inside a virtual environment, otherwise, virtual environment’s pip will be confused. See this answer for more details.


回答 4

最好的方法是安装virtualenv,不需要--user混乱。您将获得更大的灵活性,而不必担心每次pip安装软件包时都会破坏不同的python版本和项目。

https://virtualenv.pypa.io/en/stable/

Best way to is install virtualenv and not require the --user confusion. You will get more flexibility and not worry about clobbering the different python versions and projects everytime you pip install a package.

https://virtualenv.pypa.io/en/stable/


回答 5

在macOS上,使用该--user标志的原因是确保我们不会破坏OS依赖的库。一个保守许多的MacOS用户的做法是为了避免在安装或使用,需要一个命令更新点子sudo。因此,这包括安装到/usr/local/bin

参考:为Neovim安装python(https://github.com/zchee/deoplete-jedi/wiki/Setting-up-Python-for-Neovim

我不是所有清楚为什么安装到/usr/local/bin是鉴于该系统只依赖于Python的二进制文件在Mac上的危险/Library/Frameworks//usr/bin。我怀疑是因为如上所述,安装到/usr/local/binrequire sudo可以打开导致系统库代价高昂的错误的大门。因此,安装到内部~/.local/bin是避免这种风险的可靠方法。

参考:在Mac上使用python(https://docs.python.org/2/using/mac.html

最后,程度有安装软件包到的好处/usr/local/bin,我不知道它是有道理的,从改变目录的所有者rootuser这样可以避免必须使用,sudo同时仍可以防止进行依赖于系统的更改。*这是否是安全性默认设置,它是过去更频繁地使用Unix系统(作为服务器)的结果吗?或者至少,对于不托管服务器的Mac用户,这是一个好方法吗?

*注意:Mac的系统完整性保护(SIP)功能似乎还可以保护用户免于更改依赖于系统的库。

-E

On macOS, the reason for using the --user flag is to make sure we don’t corrupt the libraries the OS relies on. A conservative approach for many macOS users is to avoid installing or updating pip with a command that requires sudo. Thus, this includes installing to /usr/local/bin

Ref: Installing python for Neovim (https://github.com/zchee/deoplete-jedi/wiki/Setting-up-Python-for-Neovim)

I’m not all clear why installing into /usr/local/bin is a risk on a Mac given the fact that the system only relies on python binaries in /Library/Frameworks/ and /usr/bin. I suspect it’s because as noted above, installing into /usr/local/bin requires sudo which opens the door to making a costly mistake with the system libraries. Thus, installing into ~/.local/bin is a sure fire way to avoid this risk.

Ref: Using python on a Mac (https://docs.python.org/2/using/mac.html)

Finally, to the degree there is a benefit of installing packages into the /usr/local/bin, I wonder if it makes sense to change the owner of the directory from root to user? This would avoid having to use sudo while still protecting against making system-dependent changes.* Is this a security default a relic of how Unix systems were more often used in the past (as servers)? Or at minimum, just a good way to go for Mac users not hosting a server?

*Note: Mac’s System Integrity Protection (SIP) feature also seems to protect the user from changing the system-dependent libraries.

– E


回答 6

没有虚拟环境

pip <command> --user 更改当前pip命令的范围,使其在当前用户帐户的本地python软件包安装位置(而不是系统范围的软件包安装位置)上起作用,这是默认设置。

  • 请参阅《 PIP用户指南》中的“ 用户安装 ”。

这仅在多用户计算机上才真正重要。安装到系统位置的所有内容都将对所有用户可见,因此,安装到该用户位置将使该软件包安装与其他用户分开(他们不会看到该软件包,因此必须自己单独安装才能使用)。因为可能存在版本冲突,所以安装具有其他软件包所需要的依赖关系的软件包可能会引起问题,因此最好不要将给定用户使用的所有软件包推送到系统安装位置。

  • 如果是单用户计算机,则安装到该--user位置几乎没有差异。它将被安装到一个不同的文件夹中,该文件夹可能或不需要添加到路径中,具体取决于软件包及其使用方式(许多软件包都安装了命令行工具,这些工具必须位于要从外壳程序运行的路径上) 。
  • 如果它是多用户计算机,--user则首选使用root / sudo或要求管理员安装并影响每个用户的Python环境,除非管理员希望默认情况下使所有用户都能使用常规软件包。
    • 注意: 根据评论,在大多数Unix / Linux安装中,已经指出系统安装应使用常规的软件包管理器,例如apt,而不是pip

使用虚拟环境

--user在活动的venv / virtualenv环境中,该选项将安装到本地用户python位置(与没有虚拟环境时相同)。

默认情况下,软件包已安装到虚拟环境,但是如果使用--user它,将强制将其安装在虚拟环境之外的用户python脚本目录中(在Windows中,当前c:\users\<username>\appdata\roaming\python\python37\scripts适用于Python 3.7)。

但是,您将无法从虚拟环境中访问系统或用户安装(即使您--user在虚拟环境中使用过)。

如果使用--system-site-packages参数安装虚拟环境,则可以访问python的系统脚本文件夹。我相信这也包括用户python脚本文件夹,但是我不确定。但是,这样做可能会产生意想不到的后果,并且它不是使用虚拟环境的预期方式。


Python系统和本地用户安装文件夹的位置

您可以使用找到python用户安装文件夹的位置python -m site --user-base。我在“问题与解答”,文档中发现有冲突的信息,并且实际上在PC上使用此命令来确定默认值,但它们位于用户主目录(~* nix中的快捷方式,c:\users\<username>通常用于Windows)下。


其他详情

--user选项并非对每个命令都有效。例如,pip uninstall将在安装了软件包的位置(用户文件夹,虚拟环境文件夹等)中查找和卸载软件包,并且该--user选项无效。

随同pip install --user安装的东西将安装在本地位置,该位置只能由当前用户帐户查看,并且不需要root用户访问权限(在* nix上)或管理员访问权限(在Windows上)。

--user选项会修改所有 pip接受该命令的命令,以便在用户安装文件夹中查看/操作,因此,如果使用pip list --user该选项,则只会显示您使用进行安装的软件包pip install --user

Without Virtual Environments

pip <command> --user changes the scope of the current pip command to work on the current user account’s local python package install location, rather than the system-wide package install location, which is the default.

This only really matters on a multi-user machine. Anything installed to the system location will be visible to all users, so installing to the user location will keep that package installation separate from other users (they will not see it, and would have to install it themselves separately to use it). Because there can be version conflicts, installing a package with dependencies needed by other packages can cause problems, so it’s best not to push all packages a given user uses to the system install location.

  • If it is a single-user machine, there is little or no difference to installing to the --user location. It will be installed to a different folder, that may or may not need to be added to the path, depending on the package and how it’s used (many packages install command-line tools that must be on the path to run from a shell).
  • If it is a multi-user machine, --user is preferred to using root/sudo or requiring administrator installation and affecting the Python environment of every user, except in cases of general packages that the administrator wants to make available to all users by default.
    • Note: Per comments, on most Unix/Linux installs it has been pointed out that system installs should use the general package manager, such as apt, rather than pip.

With Virtual Environments

The --user option in an active venv/virtualenv environment will install to the local user python location (same as without a virtual environment).

Packages are installed to the virtual environment by default, but if you use --user it will force it to install outside the virtual environments, in the users python script directory (in Windows, this currently is c:\users\<username>\appdata\roaming\python\python37\scripts for me with Python 3.7).

However, you won’t be able to access a system or user install from within virtual environment (even if you used --user while in a virtual environment).

If you install a virtual environment with the --system-site-packages argument, you will have access to the system script folder for python. I believe this included the user python script folder as well, but I’m unsure. However, there may be unintended consequences for this and it is not the intended way to use virtual environments.


Location of the Python System and Local User Install Folders

You can find the location of the user install folder for python with python -m site --user-base. I’m finding conflicting information in Q&A’s, the documentation and actually using this command on my PC as to what the defaults are, but they are underneath the user home directory (~ shortcut in *nix, and c:\users\<username> typically for Windows).


Other Details

The --user option is not a valid for every command. For example pip uninstall will find and uninstall packages wherever they were installed (in the user folder, virtual environment folder, etc.) and the --user option is not valid.

Things installed with pip install --user will be installed in a local location that will only be seen by the current user account, and will not require root access (on *nix) or administrator access (on Windows).

The --user option modifies all pip commands that accept it to see/operate on the user install folder, so if you use pip list --user it will only show you packages installed with pip install --user.


回答 7

为什么不将可执行文件放在$ PATH中

~/.local/bin directory从理论上讲应该在您的计算机中$PATH

根据这些人 说法,$PATH在使用时不添加它是一个错误systemd

该答案对其进行了更广泛的解释。

但是,即使你的发行版包括~/.local/bin目录$PATH,它可能是以下形式(内~/.profile):

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

如果该目录以前不在目录中,则需要注销并再次登录

Why not just put an executable somewhere in my $PATH

~/.local/bin directory is theoretically expected to be in your $PATH.

According to these people it’s a bug not adding it in the $PATH when using systemd.

This answer explains it more extensively.

But even if your distro includes the ~/.local/bin directory to the $PATH, it might be in the following form (inside ~/.profile):

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

which would require you to logout and login again, if the directory was not there before.


如何使用pip一次安装多个python软件包

问题:如何使用pip一次安装多个python软件包

我知道这是一种简单的方法,但是我在这里和Google上都找不到。所以我很好奇是否有办法使用pip安装多个软件包。就像是:

pip install progra1 , progra2 ,progra3 ,progra4 . 

要么:

pip install (command to read some txt containing the name of the modules) 

I know it’s an easy way of doing it but i didn’t find it neither here nor on google. So i was curious if there is a way to install multiple packages using pip. Something like:

pip install progra1 , progra2 ,progra3 ,progra4 . 

or:

pip install (command to read some txt containing the name of the modules) 

回答 0

要在命令行上安装多个软件包,只需将它们作为以空格分隔的列表传递,例如:

pip install wsgiref boto

要从文本文件安装,请从pip install --help

-r FILENAME,-requirement = FILENAME

安装给定需求文件中列出的所有软件包。此选项可以多次使用。

查看有关需求文件的一般布局和语法的pip文档 -请注意,pip freeze如果需要快速的示例,则可以根据当前环境/站点程序包生成一个pip文档 -例如(基于已安装的文件wsgirefboto干净的virtualenv文件) ):

$ pip freeze
boto==2.3.0
wsgiref==0.1.2

For installing multiple packages on the command line, just pass them as a space-delimited list, e.g.:

pip install wsgiref boto

For installing from a text file, then, from pip install --help:

-r FILENAME, –requirement=FILENAME

Install all the packages listed in the given requirements file. This option can be used multiple times.

Take a look at the pip documentation regarding requirements files for their general layout and syntax – note that you can generate one based on current environment / site-packages with pip freeze if you want a quick example – e.g. (based on having installed wsgiref and boto in a clean virtualenv):

$ pip freeze
boto==2.3.0
wsgiref==0.1.2

回答 1

pip install -r requirements.txt

然后在requirements.txt文件中,将模块放入列表,每行列出一项。

  • 的Django = 1.3.1

  • 南方> = 0.7

  • django-debug-工具栏

pip install -r requirements.txt

and in the requirements.txt file you put your modules in a list, with one item per line.

  • Django=1.3.1

  • South>=0.7

  • django-debug-toolbar


回答 2

您可以安装称为需求文件的文本文件中列出的软件包。例如,如果您有一个名为的文件,req.txt其中包含以下文本:

Django==1.4
South==0.7.3

然后在命令行中发出:

pip install -r req.txt

pip将安装特定版本的文件中列出的软件包。

You can install packages listed in a text file called requirements file. For example, if you have a file called req.txt containing the following text:

Django==1.4
South==0.7.3

and you issue at the command line:

pip install -r req.txt

pip will install packages listed in the file at the specific revisions.


回答 3

作为其他答案的补充,您可以使用该选项--no-cache-dir禁用pip中的缓存。使用一次安装多个软件包时,我的虚拟机崩溃了pip install -r requirements.txt。为我解决的是:

pip install --no-cache-dir -r requirements.txt

Complementing the other answers, you can use the option --no-cache-dir to disable caching in pip. My virtual machine was crashing when installing many packages at once with pip install -r requirements.txt. What solved for me was:

pip install --no-cache-dir -r requirements.txt

回答 4

提供与安装单个模块时相同的命令,仅通过空格分隔的格式传递它

give the same command as you used to give while installing a single module only pass it via space delimited format