标签归档:pip

pip install -U中的“ -U”选项代表什么

问题:pip install -U中的“ -U”选项代表什么

尽管有大量Google搜索,但我找不到pip命令行选项/参数的任何文档。什么pip install -U意思 是否有人链接到pip选项和参数列表?

Despite a ton of Googling, I can’t find any docs for pip’s command line options/arguments. What does pip install -U mean? Does anyone have a link to a list of pip’s options and arguments?


回答 0

键入pip install -h列出帮助:

-U,–upgrade将所有软件包升级到最新可用版本

因此,如果您已经安装了软件包,它将为您升级该软件包。如果没有-U开关,它将告诉您该软件包已安装并退出。

每个pip子命令都有其自己的帮助列表。pip -h向您显示总体帮助,并pip [subcommand] -h为该子命令提供帮助,例如install

您也可以在线找到完整的参考文档。“ 常规选项”部分涵盖了每个pip子命令可用的开关,而每个子命令都有一个单独的“ 选项”部分来涵盖特定于子命令的开关;例如,请参阅“ pip install选项”部分

Type pip install -h to list help:

-U, –upgrade Upgrade all packages to the newest available version

So, if you already have a package installed, it will upgrade the package for you. Without the -U switch it’ll tell you the package is already installed and exit.

Each pip subcommand has its own help listing. pip -h shows you overall help, and pip [subcommand] -h gives you help for that sub command, such as install.

You can also find the full reference documentation online; the General Options section covers switches available for every pip subcommand, while each subcommand has a separate Options section to cover subcommand-specific switches; see the pip install options section, for example.


使用pip为特定的python版本安装模块

问题:使用pip为特定的python版本安装模块

在Ubuntu 10.04上,默认情况下安装了Python 2.6,然后我安装了Python 2.7。如何使用pip installPython 2.7安装软件包。

例如:

pip install beautifulsoup4

默认情况下会为Python 2.6安装BeautifulSoup

当我做:

import bs4

在Python 2.6中可以使用,但在Python 2.7中可以显示:

No module named bs4

On Ubuntu 10.04 by default Python 2.6 is installed, then I have installed Python 2.7. How can I use pip install to install packages for Python 2.7.

For example:

pip install beautifulsoup4

by default installs BeautifulSoup for Python 2.6

When I do:

import bs4

in Python 2.6 it works, but in Python 2.7 it says:

No module named bs4

回答 0

pip对要安装新软件包的Python实例使用已安装的版本。

在许多发行版中,可能会有单独的python2.6-pippython2.7-pip程序包,并使用诸如pip-2.6和的二进制名称来调用pip-2.7。如果未将pip打包到所需目标的发行版中,则可能需要寻找setuptools或easyinstall软件包,或使用virtualenv(在生成的环境中始终包含pip)。

如果您在发行版中找不到任何内容,请在pip的网站上提供安装说明

Use a version of pip installed against the Python instance you want to install new packages to.

In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).

pip’s website includes installation instructions, if you can’t find anything within your distribution.


回答 1

另外,由于pip其本身是用python编写的,因此您可以使用要为其安装软件包的python版本进行调用:

python2.7 -m pip install foo

Alternatively, since pip itself is written in python, you can just call it with the python version you want to install the package for:

python2.7 -m pip install foo

回答 2

您可以使用相应的python为特定的python版本执行 pip模块:

Python 2.6:

python2.6 -m pip install beautifulsoup4

Python 2.7

python2.7 -m pip install beautifulsoup4

You can execute pip module for a specific python version using the corresponding python:

Python 2.6:

python2.6 -m pip install beautifulsoup4

Python 2.7

python2.7 -m pip install beautifulsoup4

回答 3

您可以使用此语法

python_version -m pip install your_package

例如。如果您正在运行python3.5,则将其命名为“ python3”,并想安装numpy软件包

python3 -m pip install numpy

You can use this syntax

python_version -m pip install your_package

For example. If you’re running python3.5, you named it as “python3”, and want to install numpy package

python3 -m pip install numpy

回答 4

在Windows中,您可以通过提及python版本来执行pip模块(您需要确保启动器在您的路径上)

py -2 -m pip install pyfora

In Windows, you can execute the pip module by mentioning the python version ( You need to ensure that the launcher is on your path )

py -2 -m pip install pyfora

回答 5

另外,如果您想使用特定版本的python安装软件包的特定版本,可以采用这种方法

sudo python2.7 -m pip install pyudev=0.16

如果“ =”无效,请使用==

x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev=0.16

无效的要求:’pyudev = 0.16’=不是有效的运算符。你是说==吗?

x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev==0.16

工作良好

Alternatively, if you want to install specific version of the package with the specific version of python, this is the way

sudo python2.7 -m pip install pyudev=0.16

if the “=” doesnt work, use ==

x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev=0.16

Invalid requirement: ‘pyudev=0.16’ = is not a valid operator. Did you mean == ?

x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev==0.16

works fine


回答 6

Python 2

sudo pip2 install johnbonjovi  

Python 3

sudo pip3 install johnbonjovi

Python 2

sudo pip2 install johnbonjovi  

Python 3

sudo pip3 install johnbonjovi

回答 7

如果您同时安装了2.7和3.x版本的python,则只需将python 3.x版本的python exe文件重命名为类似的名称-将“ python.exe”重命名为“ python3.exe”。现在,您可以将pip分别用于两个版本。如果您通常键入“ pip install”,则默认情况下将考虑2.7版本。如果要在3.x版本上安装它,则需要将命令调用为“ python3 -m pip install”。

If you have both 2.7 and 3.x versions of python installed, then just rename the python exe file of python 3.x version to something like – “python.exe” to “python3.exe”. Now you can use pip for both versions individually. If you normally type “pip install ” it will consider the 2.7 version by default. If you want to install it on the 3.x version you need to call the command as “python3 -m pip install “.


回答 8

对于Python 3

sudo apt-get install python3-pip
sudo pip3 install beautifulsoup4

对于Python 2

sudo apt-get install python2-pip
sudo pip2 install beautifulsoup4

在Debian / Ubuntu上, pip是在安装适用于Python 2的软件包时使用的命令,pip3而是在安装适用于Python 3的软件包时使用的命令。

For Python 3

sudo apt-get install python3-pip
sudo pip3 install beautifulsoup4

For Python 2

sudo apt-get install python2-pip
sudo pip2 install beautifulsoup4

On Debian/Ubuntu, pip is the command to use when installing packages for Python 2, while pip3 is the command to use when installing packages for Python 3.


回答 9

对于python2使用:

py -2 -m pip install beautifulsoup4

for python2 use:

py -2 -m pip install beautifulsoup4

回答 10

与其他任何python脚本一样,您可以指定运行它的python安装。您可以将其放在外壳配置文件中以保存别名。该$1指的是你传递给脚本的第一个参数。

# PYTHON3 PIP INSTALL V2
alias pip_install3="python3 -m $(which pip) install $1"

As with any other python script, you may specify the python installation you’d like to run it with. You may put this in your shell profile to save the alias. The $1 refers to the first argument you pass to the script.

# PYTHON3 PIP INSTALL V2
alias pip_install3="python3 -m $(which pip) install $1"

回答 11

我在Windows上通过Chocolatey安装了Python 2.7 ,并在pip2.7.exe中找到了C:\tools\python2\Scripts

使用此可执行文件而不是pip命令为我安装了正确的模块(requests对于Python 2.7)。

I had Python 2.7 installed via chocolatey on Windows and found pip2.7.exe in C:\tools\python2\Scripts.

Using this executable instead of the pip command installed the correct module for me (requests for Python 2.7).


回答 12

我在另一个名为Twisted的软件包中也遇到了类似的问题。我想为Python 2.7安装它,但仅为Python 2.6(系统的默认版本)安装了它。

进行简单的更改对我有用。

在将Python 2.7的路径添加到$PATH变量时,请像这样将其追加到前面:PATH=/usr/local/bin:$PATH,以便系统使用该版本。

如果您遇到更多问题,可以关注这篇对我有帮助的博客文章-https: //github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence仅用于centos机器

I faced a similar problem with another package called Twisted. I wanted to install it for Python 2.7, but it only got installed for Python 2.6 (system’s default version).

Making a simple change worked for me.

When adding Python 2.7’s path to your $PATH variable, append it to the front like this: PATH=/usr/local/bin:$PATH, so that the system uses that version.

If you face more problems, you can follow this blog post which helped me – https://github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence-exactly-for-centos-machine-only


使用Requirements.txt安装时,避免在单个软件包上出现故障

问题:使用Requirements.txt安装时,避免在单个软件包上出现故障

我正在从安装软件包 requirements.txt

pip install -r requirements.txt

requirements.txt文件显示为:

Pillow
lxml
cssselect
jieba
beautifulsoup
nltk

lxml是唯一无法安装的软件包,这将导致一切失败(larsk在注释中指出了预期的结果)。但是,lxml失败后pip仍会继续运行并下载其余软件包。

据我了解,pip install -r requirements.txt如果requirements.txt无法安装中列出的任何软件包,该命令将失败。

我在运行时可以传递任何参数pip install -r requirements.txt来告诉它安装可以执行的操作并跳过不能执行的程序包,或者在看到失败后立即退出吗?

I am installing packages from requirements.txt

pip install -r requirements.txt

The requirements.txt file reads:

Pillow
lxml
cssselect
jieba
beautifulsoup
nltk

lxml is the only package failing to install and this leads to everything failing (expected results as pointed out by larsks in the comments). However, after lxml fails pip still runs through and downloads the rest of the packages.

From what I understand the pip install -r requirements.txt command will fail if any of the packages listed in the requirements.txt fail to install.

Is there any argument I can pass when running pip install -r requirements.txt to tell it to install what it can and skip the packages that it cannot, or to exit as soon as it sees something fail?


回答 0

运行每一行pip install可能是一种解决方法。

cat requirements.txt | xargs -n 1 pip install

注意:该-a参数在MacOS下不可用,因此老猫更便携。

Running each line with pip install may be a workaround.

cat requirements.txt | xargs -n 1 pip install

Note: -a parameter is not available under MacOS, so old cat is more portable.


回答 1

该解决方案处理您的requirements.txt中的空行,空白行,#注释行,whitespace-then-#注释行。

cat requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 pip install

帽尖到这个答案的sed的魔法。

This solution handles empty lines, whitespace lines, # comment lines, whitespace-then-# comment lines in your requirements.txt.

cat requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 pip install

Hat tip to this answer for the sed magic.


回答 2

对于Windows:

点版本> = 18

import sys
from pip._internal import main as pip_main

def install(package):
    pip_main(['install', package])

if __name__ == '__main__':
    with open(sys.argv[1]) as f:
        for line in f:
            install(line)

点版本<18

import sys
import pip

def install(package):
    pip.main(['install', package])

if __name__ == '__main__':
    with open(sys.argv[1]) as f:
        for line in f:
            install(line)

For Windows:

pip version >=18

import sys
from pip._internal import main as pip_main

def install(package):
    pip_main(['install', package])

if __name__ == '__main__':
    with open(sys.argv[1]) as f:
        for line in f:
            install(line)

pip version <18

import sys
import pip

def install(package):
    pip.main(['install', package])

if __name__ == '__main__':
    with open(sys.argv[1]) as f:
        for line in f:
            install(line)

回答 3

xargs解决方案有效,但可能会存在可移植性问题(BSD / GNU),并且/或者如果您的需求文件中有注释或空白行,则可能会很麻烦。

至于需要这种行为的用例,例如,我使用了两个单独的需求文件,一个仅列出需要始终安装的核心依赖关系,而另一个文件则列出了90%的具有非核心依赖关系的文件。大多数用例都不需要。这相当于Recommendsdebian软件包的这一部分。

我使用以下shell脚本(requires sed)安装可选的依赖项

#!/bin/sh

while read dependency; do
    dependency_stripped="$(echo "${dependency}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    # Skip comments
    if [[ $dependency_stripped == \#* ]]; then
        continue
    # Skip blank lines
    elif [ -z "$dependency_stripped" ]; then
        continue
    else
        if pip install "$dependency_stripped"; then
            echo "$dependency_stripped is installed"
        else
            echo "Could not install $dependency_stripped, skipping"
        fi
    fi
done < recommends.txt

The xargs solution works but can have portability issues (BSD/GNU) and/or be cumbersome if you have comments or blank lines in your requirements file.

As for the usecase where such a behavior would be required, I use for instance two separate requirement files, one which is only listing core dependencies that need to be always installed and another file with non-core dependencies that are in 90% of the cases not needed for most usecases. That would be an equivalent of the Recommends section of a debian package.

I use the following shell script (requires sed) to install optional dependencies:

#!/bin/sh

while read dependency; do
    dependency_stripped="$(echo "${dependency}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    # Skip comments
    if [[ $dependency_stripped == \#* ]]; then
        continue
    # Skip blank lines
    elif [ -z "$dependency_stripped" ]; then
        continue
    else
        if pip install "$dependency_stripped"; then
            echo "$dependency_stripped is installed"
        else
            echo "Could not install $dependency_stripped, skipping"
        fi
    fi
done < recommends.txt

回答 4

谢谢Etienne Prothon提供的Windows保护套。

但是,升级到pip 18后,pip包不会将main公开。因此,您可能需要像这样更改代码。

 # This code install line by line a list of pip package 
 import sys
 from pip._internal import main as pip_main

 def install(package):
    pip_main(['install', package])

 if __name__ == '__main__':
    with open(sys.argv[1]) as f:
        for line in f:
            install(line)

Thanks, Etienne Prothon for windows cases.

But, after upgrading to pip 18, pip package don’t expose main to public. So you may need to change code like this.

 # This code install line by line a list of pip package 
 import sys
 from pip._internal import main as pip_main

 def install(package):
    pip_main(['install', package])

 if __name__ == '__main__':
    with open(sys.argv[1]) as f:
        for line in f:
            install(line)

回答 5

对于Windows:

import os
from pip.__main__ import _main as main

error_log = open('error_log.txt', 'w')

def install(package):
    try:
        main(['install'] + [str(package)])
    except Exception as e:
        error_log.write(str(e))

if __name__ == '__main__':
    f = open('requirements1.txt', 'r')
    for line in f:
        install(line)
    f.close()
    error_log.close()
  1. 创建一个本地目录,然后将requirements.txt文件放入其中。
  2. 复制上面的代码,并将其另存为python文件在同一目录中。.py例如,请记住使用扩展名,install_packages.py
  3. 使用cmd运行此文件: python install_packages.py
  4. 提到的所有软件包都将一口气安装起来,而无需停止。:)

您可以在安装功能中添加其他参数。喜欢: main(['install'] + [str(package)] + ['--update'])

For Windows:

import os
from pip.__main__ import _main as main

error_log = open('error_log.txt', 'w')

def install(package):
    try:
        main(['install'] + [str(package)])
    except Exception as e:
        error_log.write(str(e))

if __name__ == '__main__':
    f = open('requirements1.txt', 'r')
    for line in f:
        install(line)
    f.close()
    error_log.close()
  1. Create a local directory, and put your requirements.txt file in it.
  2. Copy the code above and save it as a python file in the same directory. Remember to use .py extension, for instance, install_packages.py
  3. Run this file using a cmd: python install_packages.py
  4. All the packages mentioned will be installed in one go without stopping at all. :)

You can add other parameters in install function. Like: main(['install'] + [str(package)] + ['--update'])


我可以使用`pip`代替`easy_install`来实现`python setup.py install`依赖关系解析吗?

问题:我可以使用`pip`代替`easy_install`来实现`python setup.py install`依赖关系解析吗?

python setup.py install会自动安装requires=[]使用中列出的软件包easy_install。我该如何使用它pip呢?

python setup.py install will automatically install packages listed in requires=[] using easy_install. How do I get it to use pip instead?


回答 0

是的你可以。您可以从网络或计算机上的tarball或文件夹中安装软件包。例如:

从网络上的tarball安装

pip install https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz

从本地tarball安装

wget https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz
pip install requests-2.3.0.tar.gz

从本地文件夹安装

tar -zxvf requests-2.3.0.tar.gz
cd requests-2.3.0
pip install .

您可以删除requests-2.3.0文件夹。

从本地文件夹安装(可编辑模式)

pip install -e .

这将以可编辑模式安装软件包。您对代码所做的任何更改将立即在整个系统中应用。如果您是程序包开发人员并且想要测试更改,这将很有用。这也意味着您必须在不中断安装的情况下删除文件夹。

Yes you can. You can install a package from a tarball or a folder, on the web or your computer. For example:

Install from tarball on web

pip install https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz

Install from local tarball

wget https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz
pip install requests-2.3.0.tar.gz

Install from local folder

tar -zxvf requests-2.3.0.tar.gz
cd requests-2.3.0
pip install .

You can delete the requests-2.3.0 folder.

Install from local folder (editable mode)

pip install -e .

This installs the package in editable mode. Any changes you make to the code will immediately apply across the system. This is useful if you are the package developer and want to test changes. It also means you can’t delete the folder without breaking the install.


回答 1

您可以先pip install归档python setup.py sdist。您也pip install -e .可以像python setup.py develop

You can pip install a file perhaps by python setup.py sdist first. You can also pip install -e . which is like python setup.py develop.


回答 2

如果您真的python setup.py install愿意使用,可以尝试如下操作:

from setuptools import setup, find_packages
from setuptools.command.install import install as InstallCommand


class Install(InstallCommand):
    """ Customized setuptools install command which uses pip. """

    def run(self, *args, **kwargs):
        import pip
        pip.main(['install', '.'])
        InstallCommand.run(self, *args, **kwargs)


setup(
    name='your_project',
    version='0.0.1a',
    cmdclass={
        'install': Install,
    },
    packages=find_packages(),
    install_requires=['simplejson']
)

If you are really set on using python setup.py install you could try something like this:

from setuptools import setup, find_packages
from setuptools.command.install import install as InstallCommand


class Install(InstallCommand):
    """ Customized setuptools install command which uses pip. """

    def run(self, *args, **kwargs):
        import pip
        pip.main(['install', '.'])
        InstallCommand.run(self, *args, **kwargs)


setup(
    name='your_project',
    version='0.0.1a',
    cmdclass={
        'install': Install,
    },
    packages=find_packages(),
    install_requires=['simplejson']
)

virtualenv –no-site-packages和pip仍在查找全局软件包吗?

问题:virtualenv –no-site-packages和pip仍在查找全局软件包吗?

我印象中virtualenv --no-site-packages会创建一个完全独立和隔离的Python环境,但事实并非如此。

例如,我在全局安装了python-django,但希望使用其他Django版本创建virtualenv。

$ virtualenv --no-site-packages foo       
New python executable in foo/bin/python
Installing setuptools............done.
$ pip -E foo install Django
Requirement already satisfied: Django in /usr/share/pyshared
Installing collected packages: Django
Successfully installed Django

据我所知,pip -E foo install以上内容应该重新安装新版本的Django。另外,如果我告诉pip冻结环境,则会得到很多软件包。我希望对于一个新鲜的环境来说--no-site-packages这是空白?

$ pip -E foo freeze
4Suite-XML==1.0.2
BeautifulSoup==3.1.0.1
Brlapi==0.5.3
BzrTools==1.17.0
Django==1.1
... and so on ...

我是否误解了--no-site-packages应该如何工作?

I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn’t seem to.

For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.

$ virtualenv --no-site-packages foo       
New python executable in foo/bin/python
Installing setuptools............done.
$ pip -E foo install Django
Requirement already satisfied: Django in /usr/share/pyshared
Installing collected packages: Django
Successfully installed Django

From what I can tell, the pip -E foo install above is supposed to re-install a new version of Django. Also, if I tell pip to freeze the environment, I get a whole lot of packages. I would expect that for a fresh environment with --no-site-packages this would be blank?

$ pip -E foo freeze
4Suite-XML==1.0.2
BeautifulSoup==3.1.0.1
Brlapi==0.5.3
BzrTools==1.17.0
Django==1.1
... and so on ...

Am I misunderstanding how --no-site-packages is supposed to work?


回答 0

我遇到了这样的问题,直到意识到(早于发现virtualenv),我就开始在.bashrc文件中的PYTHONPATH中添加目录。由于已经过去一年多了,所以我没有马上想到。

I had a problem like this, until I realized that (long before I had discovered virtualenv), I had gone adding directories to the PYTHONPATH in my .bashrc file. As it had been over a year beforehand, I didn’t think of that straight away.


回答 1

您必须确保pip在创建的虚拟环境中而不是全局环境中运行二进制文件。

env/bin/pip freeze

查看测试:

我们使用以下--no-site-packages选项创建virtualenv :

$ virtualenv --no-site-packages -p /usr/local/bin/python mytest
Running virtualenv with interpreter /usr/local/bin/python
New python executable in mytest/bin/python
Installing setuptools, pip, wheel...done.

我们检查freeze新创建的的输出pip

$ mytest/bin/pip freeze
argparse==1.3.0
wheel==0.24.0

但是,如果我们使用global pip,那么我们将得到:

$ pip freeze
...
pyxdg==0.25
...
range==1.0.0
...
virtualenv==13.1.2

即,pip已在整个系统中安装的所有软件包。通过检查,which pip我们得到了(至少在我的情况下)类似的东西/usr/local/bin/pip,这意味着当我们这样做时pip freeze,将调用此二进制文件而不是mytest/bin/pip

You have to make sure you are running the pip binary in the virtual environment you created, not the global one.

env/bin/pip freeze

See a test:

We create the virtualenv with the --no-site-packages option:

$ virtualenv --no-site-packages -p /usr/local/bin/python mytest
Running virtualenv with interpreter /usr/local/bin/python
New python executable in mytest/bin/python
Installing setuptools, pip, wheel...done.

We check the output of freeze from the newly created pip:

$ mytest/bin/pip freeze
argparse==1.3.0
wheel==0.24.0

But if we do use the global pip, this is what we get:

$ pip freeze
...
pyxdg==0.25
...
range==1.0.0
...
virtualenv==13.1.2

That is, all the packages that pip has installed in the whole system. By checking which pip we get (at least in my case) something like /usr/local/bin/pip, meaning that when we do pip freeze it is calling this binary instead of mytest/bin/pip.


回答 2

最终,我发现无论出于什么原因,pip -E都无法正常工作。但是,如果我实际上激活了virtualenv,并使用virtualenv提供的easy_install来安装pip,然后直接从内部使用pip,那么它似乎可以正常工作,并且只显示virtualenv中的软件包。

Eventually I found that, for whatever reason, pip -E was not working. However, if I actually activate the virtualenv, and use easy_install provided by virtualenv to install pip, then use pip directly from within, it seems to work as expected and only show the packages in the virtualenv


回答 3

我知道这是一个非常老的问题,但是对于那些来到这里寻求解决方案的人来说:

运行之前不要忘记激活virtualenvsource bin/activatepip freeze。否则,您将获得所有全局软件包的列表。

I know this is a very old question but for those arriving here looking for a solution:

Don’t forget to activate the virtualenv (source bin/activate) before running pip freeze. Otherwise you’ll get a list of all global packages.


回答 4

暂时清除PYTHONPATH带有:

export PYTHONPATH=

然后创建并激活虚拟环境:

virtualenv foo
. foo/bin/activate

只有这样:

pip freeze

Temporarily clear the PYTHONPATH with:

export PYTHONPATH=

Then create and activate the virtual environment:

virtualenv foo
. foo/bin/activate

Only then:

pip freeze

回答 5

--no-site-packages顾名思义,应该从中删除标准site-packages目录sys.path。保留在标准Python路径中的所有其他内容都将保留在那里。

--no-site-packages should, as the name suggests, remove the standard site-packages directory from sys.path. Anything else that lives in the standard Python path will remain there.


回答 6

如果直接调用脚本script.py,则在Windows 上可能会发生类似的问题,因为脚本随后使用Windows默认打开器并在虚拟环境之外打开Python。调用它将python script.py在虚拟环境中使用Python。

A similar problem can occur on Windows if you call scripts directly as script.py which then uses the Windows default opener and opens Python outside the virtual environment. Calling it with python script.py will use Python with the virtual environment.


回答 7

当您将virtualenv目录移动到另一个目录(在linux上)或重命名父目录时,似乎也会发生这种情况。

This also seems to happen when you move the virtualenv directory to another directory (on linux), or rename a parent directory.


回答 8

我遇到了同样的问题。对我来说(在Ubuntu上)的问题是我的路径名包含$。当我在$ dir之外创建一个virtualenv时,它工作正常。

奇怪的。

I was having this same problem. The issue for me (on Ubuntu) was that my path name contained $. When I created a virtualenv outside of the $ dir, it worked fine.

Weird.


回答 9

virtualenv pip无法正常工作的可能原因之一是,如果任何父文件夹的名称中都有空格/Documents/project name/app 重命名以/Documents/projectName/app解决该问题。

One of the possible reasons why virtualenv pip won’t work is if any of the parent folders had space in its name /Documents/project name/app renaming it to /Documents/projectName/app solves the problem.


回答 10

我遇到了同样的问题,即venv中的点仍然可以用作全局点。
搜索很多页面后,我以这种方式解决了。
1.通过virtualenv使用选项“ –no-site-packages”创建一个新的venv

virtualenv --no-site-packages --python=/xx/xx/bin/python my_env_nmae

请注意,尽管从Virtualenv的doc文件中的1.7.0版本开始,“-no-site-packages”选项默认为true,但是我发现它除非您手动将其设置为不起作用。为了获得纯净的venv,我强烈建议打开2。激活您创建的新env

source ./my_env_name/bin/activate
  1. 检查您的pip位置和python位置,并确保这两个命令在虚拟环境下
pip --version
which python
  1. 在虚拟环境下使用pip安装不受全局软件包中断影响的软件包
pip install package_name

希望这个答案对您有帮助!

I came accross the same problem where pip in venv still works as global pip.
After searching many pages, i figure it out this way.
1. Create a new venv by virtualenv with option “–no-site-packages”

virtualenv --no-site-packages --python=/xx/xx/bin/python my_env_nmae

please note that although the “–no-site-packages” option was default true since 1.7.0 in the doc file of virtualenv, but i found it not working unless you set it on manually. In order to get a pure venv, i strongly suggest turning this option on 2. Activate the new env you created

source ./my_env_name/bin/activate
  1. Check your pip location and python location and make sure these two commands are under virtual envirement
pip --version
which python
  1. Use pip under virtual env to install packages free from the global packages interuption
pip install package_name

Wish this answer helps you!


回答 11

这是所有pip安装选项的列表-我没有找到任何’ -E‘选项,可能是较旧的版本。下面,我virtualenv将为即将到来的SO用户提供简单的英语用法和使用方法。


一切似乎都不错,请接受激活virtualenvfoo)。它所要做的就是允许我们拥有多个(和不同的)Python环境,即各种Python版本,各种Django版本或任何其他Python包-如果我们有生产中的先前版本,并且想用我们的测试最新的Django版本应用。

简而言之,创建和使用(激活)虚拟环境(virtualenv)使得可以使用不同的Python解释器(即python 2.7和3.3)运行或测试我们的应用程序或简单的python脚本-可以全新安装(使用--no-site-packages选项),也可以使用现有的所有软件包/ last设置(使用--system-site-packages选项)。要使用它,我们必须激活它:

$ pip install django 将其安装到全局站点程序包中,并类似地获取 pip freeze will会给出全局站点程序包的名称。

而在venv dir(foo)内部执行$ source /bin/activate将激活venv,即,现在使用pip安装的所有内容都只会安装在虚拟env中,并且只有现在pip冻结将不会提供全局站点软件包python软件包的列表。一旦激活:

$ virtualenv --no-site-packages foo       
New python executable in foo/bin/python
Installing setuptools............done.
$ cd foo
$ source bin/activate 
(foo)$ pip install django

(foo)$符号表明我们正在使用虚拟python环境之前,即任何带有pip的东西-安装,冻结,卸载将仅限于该venv,并且对全局/默认Python安装/软件包没有影响。

Here’s the list of all the pip install options – I didn’t find any ‘-E‘ option, may be older version had it. Below I am sharing a plain english usage and working of virtualenv for the upcoming SO users.


Every thing seems fine, accept activating the virtualenv (foo). All it does is allow us to have multiple (and varying) python environment i.e. various Python versions, or various Django versions, or any other Python package – in case we have a previous version in production and want to test the latest Django release with our application.

In short creating and using (activating) virtual environment (virtualenv) makes it possible to run or test our application or simple python scripts with different Python interpreter i.e. Python 2.7 and 3.3 – can be a fresh installation (using --no-site-packages option) or all the packages from existing/last setup (using --system-site-packages option). To use it we have to activate it:

$ pip install django will install it into the global site-packages, and similarly getting the pip freeze will give names of the global site-packages.

while inside the venv dir (foo) executing $ source /bin/activate will activate venv i.e. now anything installed with pip will only be installed in the virtual env, and only now the pip freeze will not give the list of global site-packages python packages. Once activated:

$ virtualenv --no-site-packages foo       
New python executable in foo/bin/python
Installing setuptools............done.
$ cd foo
$ source bin/activate 
(foo)$ pip install django

(foo) before the $ sign indicates we are using a virtual python environment i.e. any thing with pip – install, freeze, uninstall will be limited to this venv, and no effect on global/default Python installation/packages.


ImportError:没有名为dateutil.parser的模块

问题:ImportError:没有名为dateutil.parser的模块

我在导入时收到以下错误pandasPython程序

monas-mbp:book mona$ sudo pip install python-dateutil
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Cleaning up...
monas-mbp:book mona$ python t1.py
No module named dateutil.parser
Traceback (most recent call last):
  File "t1.py", line 4, in <module>
    import pandas as pd
  File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
  File "tslib.pyx", line 31, in init pandas.tslib (pandas/tslib.c:48782)
ImportError: No module named dateutil.parser

这也是程序:

import codecs 
from math import sqrt
import numpy as np
import pandas as pd

users = {"Angelica": {"Blues Traveler": 3.5, "Broken Bells": 2.0,
                      "Norah Jones": 4.5, "Phoenix": 5.0,
                      "Slightly Stoopid": 1.5,
                      "The Strokes": 2.5, "Vampire Weekend": 2.0},

         "Bill":{"Blues Traveler": 2.0, "Broken Bells": 3.5,
                 "Deadmau5": 4.0, "Phoenix": 2.0,
                 "Slightly Stoopid": 3.5, "Vampire Weekend": 3.0},

         "Chan": {"Blues Traveler": 5.0, "Broken Bells": 1.0,
                  "Deadmau5": 1.0, "Norah Jones": 3.0, "Phoenix": 5,
                  "Slightly Stoopid": 1.0},

         "Dan": {"Blues Traveler": 3.0, "Broken Bells": 4.0,
                 "Deadmau5": 4.5, "Phoenix": 3.0,
                 "Slightly Stoopid": 4.5, "The Strokes": 4.0,
                 "Vampire Weekend": 2.0},

         "Hailey": {"Broken Bells": 4.0, "Deadmau5": 1.0,
                    "Norah Jones": 4.0, "The Strokes": 4.0,
                    "Vampire Weekend": 1.0},

         "Jordyn":  {"Broken Bells": 4.5, "Deadmau5": 4.0,
                     "Norah Jones": 5.0, "Phoenix": 5.0,
                     "Slightly Stoopid": 4.5, "The Strokes": 4.0,
                     "Vampire Weekend": 4.0},

         "Sam": {"Blues Traveler": 5.0, "Broken Bells": 2.0,
                 "Norah Jones": 3.0, "Phoenix": 5.0,
                 "Slightly Stoopid": 4.0, "The Strokes": 5.0},

         "Veronica": {"Blues Traveler": 3.0, "Norah Jones": 5.0,
                      "Phoenix": 4.0, "Slightly Stoopid": 2.5,
                      "The Strokes": 3.0}
        }



class recommender:

    def __init__(self, data, k=1, metric='pearson', n=5):
        """ initialize recommender
        currently, if data is dictionary the recommender is initialized
        to it.
        For all other data types of data, no initialization occurs
        k is the k value for k nearest neighbor
        metric is which distance formula to use
        n is the maximum number of recommendations to make"""
        self.k = k
        self.n = n
        self.username2id = {}
        self.userid2name = {}
        self.productid2name = {}
        # for some reason I want to save the name of the metric
        self.metric = metric
        if self.metric == 'pearson':
            self.fn = self.pearson
        #
        # if data is dictionary set recommender data to it
        #
        if type(data).__name__ == 'dict':
            self.data = data

    def convertProductID2name(self, id):
        """Given product id number return product name"""
        if id in self.productid2name:
            return self.productid2name[id]
        else:
            return id


    def userRatings(self, id, n):
        """Return n top ratings for user with id"""
        print ("Ratings for " + self.userid2name[id])
        ratings = self.data[id]
        print(len(ratings))
        ratings = list(ratings.items())
        ratings = [(self.convertProductID2name(k), v)
                   for (k, v) in ratings]
        # finally sort and return
        ratings.sort(key=lambda artistTuple: artistTuple[1],
                     reverse = True)
        ratings = ratings[:n]
        for rating in ratings:
            print("%s\t%i" % (rating[0], rating[1]))




    def loadBookDB(self, path=''):
        """loads the BX book dataset. Path is where the BX files are
        located"""
        self.data = {}
        i = 0
        #
        # First load book ratings into self.data
        #
        f = codecs.open(path + "BX-Book-Ratings.csv", 'r', 'utf8')
        for line in f:
            i += 1
            #separate line into fields
            fields = line.split(';')
            user = fields[0].strip('"')
            book = fields[1].strip('"')
            rating = int(fields[2].strip().strip('"'))
            if user in self.data:
                currentRatings = self.data[user]
            else:
                currentRatings = {}
            currentRatings[book] = rating
            self.data[user] = currentRatings
        f.close()
        #
        # Now load books into self.productid2name
        # Books contains isbn, title, and author among other fields
        #
        f = codecs.open(path + "BX-Books.csv", 'r', 'utf8')
        for line in f:
            i += 1
            #separate line into fields
            fields = line.split(';')
            isbn = fields[0].strip('"')
            title = fields[1].strip('"')
            author = fields[2].strip().strip('"')
            title = title + ' by ' + author
            self.productid2name[isbn] = title
        f.close()
        #
        #  Now load user info into both self.userid2name and
        #  self.username2id
        #
        f = codecs.open(path + "BX-Users.csv", 'r', 'utf8')
        for line in f:
            i += 1
            #print(line)
            #separate line into fields
            fields = line.split(';')
            userid = fields[0].strip('"')
            location = fields[1].strip('"')
            if len(fields) > 3:
                age = fields[2].strip().strip('"')
            else:
                age = 'NULL'
            if age != 'NULL':
                value = location + '  (age: ' + age + ')'
            else:
                value = location
            self.userid2name[userid] = value
            self.username2id[location] = userid
        f.close()
        print(i)


    def pearson(self, rating1, rating2):
        sum_xy = 0
        sum_x = 0
        sum_y = 0
        sum_x2 = 0
        sum_y2 = 0
        n = 0
        for key in rating1:
            if key in rating2:
                n += 1
                x = rating1[key]
                y = rating2[key]
                sum_xy += x * y
                sum_x += x
                sum_y += y
                sum_x2 += pow(x, 2)
                sum_y2 += pow(y, 2)
        if n == 0:
            return 0
        # now compute denominator
        denominator = (sqrt(sum_x2 - pow(sum_x, 2) / n)
                       * sqrt(sum_y2 - pow(sum_y, 2) / n))
        if denominator == 0:
            return 0
        else:
            return (sum_xy - (sum_x * sum_y) / n) / denominator


    def computeNearestNeighbor(self, username):
        """creates a sorted list of users based on their distance to
        username"""
        distances = []
        for instance in self.data:
            if instance != username:
                distance = self.fn(self.data[username],
                                   self.data[instance])
                distances.append((instance, distance))
        # sort based on distance -- closest first
        distances.sort(key=lambda artistTuple: artistTuple[1],
                       reverse=True)
        return distances

    def recommend(self, user):
       """Give list of recommendations"""
       recommendations = {}
       # first get list of users  ordered by nearness
       nearest = self.computeNearestNeighbor(user)
       #
       # now get the ratings for the user
       #
       userRatings = self.data[user]
       #
       # determine the total distance
       totalDistance = 0.0
       for i in range(self.k):
          totalDistance += nearest[i][1]
       # now iterate through the k nearest neighbors
       # accumulating their ratings
       for i in range(self.k):
          # compute slice of pie 
          weight = nearest[i][1] / totalDistance
          # get the name of the person
          name = nearest[i][0]
          # get the ratings for this person
          neighborRatings = self.data[name]
          # get the name of the person
          # now find bands neighbor rated that user didn't
          for artist in neighborRatings:
             if not artist in userRatings:
                if artist not in recommendations:
                   recommendations[artist] = (neighborRatings[artist]
                                              * weight)
                else:
                   recommendations[artist] = (recommendations[artist]
                                              + neighborRatings[artist]
                                              * weight)
       # now make list from dictionary
       recommendations = list(recommendations.items())
       recommendations = [(self.convertProductID2name(k), v)
                          for (k, v) in recommendations]
       # finally sort and return
       recommendations.sort(key=lambda artistTuple: artistTuple[1],
                            reverse = True)
       # Return the first n items
       return recommendations[:self.n]

r = recommender(users)
# The author implementation
r.loadBookDB('/Users/mona/Downloads/BX-Dump/')

ratings = pd.read_csv('/Users/danialt/BX-CSV-Dump/BX-Book-Ratings.csv', sep=";", quotechar="\"", escapechar="\\")
books = pd.read_csv('/Users/danialt/BX-CSV-Dump/BX-Books.csv', sep=";", quotechar="\"", escapechar="\\")
users = pd.read_csv('/Users/danialt/BX-CSV-Dump/BX-Users.csv', sep=";", quotechar="\"", escapechar="\\")



pivot_rating = ratings.pivot(index='User-ID', columns='ISBN', values='Book-Rating')

I am receiving the following error when importing pandas in a Python program

monas-mbp:book mona$ sudo pip install python-dateutil
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Cleaning up...
monas-mbp:book mona$ python t1.py
No module named dateutil.parser
Traceback (most recent call last):
  File "t1.py", line 4, in <module>
    import pandas as pd
  File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
  File "tslib.pyx", line 31, in init pandas.tslib (pandas/tslib.c:48782)
ImportError: No module named dateutil.parser

Also here’s the program:

import codecs 
from math import sqrt
import numpy as np
import pandas as pd

users = {"Angelica": {"Blues Traveler": 3.5, "Broken Bells": 2.0,
                      "Norah Jones": 4.5, "Phoenix": 5.0,
                      "Slightly Stoopid": 1.5,
                      "The Strokes": 2.5, "Vampire Weekend": 2.0},

         "Bill":{"Blues Traveler": 2.0, "Broken Bells": 3.5,
                 "Deadmau5": 4.0, "Phoenix": 2.0,
                 "Slightly Stoopid": 3.5, "Vampire Weekend": 3.0},

         "Chan": {"Blues Traveler": 5.0, "Broken Bells": 1.0,
                  "Deadmau5": 1.0, "Norah Jones": 3.0, "Phoenix": 5,
                  "Slightly Stoopid": 1.0},

         "Dan": {"Blues Traveler": 3.0, "Broken Bells": 4.0,
                 "Deadmau5": 4.5, "Phoenix": 3.0,
                 "Slightly Stoopid": 4.5, "The Strokes": 4.0,
                 "Vampire Weekend": 2.0},

         "Hailey": {"Broken Bells": 4.0, "Deadmau5": 1.0,
                    "Norah Jones": 4.0, "The Strokes": 4.0,
                    "Vampire Weekend": 1.0},

         "Jordyn":  {"Broken Bells": 4.5, "Deadmau5": 4.0,
                     "Norah Jones": 5.0, "Phoenix": 5.0,
                     "Slightly Stoopid": 4.5, "The Strokes": 4.0,
                     "Vampire Weekend": 4.0},

         "Sam": {"Blues Traveler": 5.0, "Broken Bells": 2.0,
                 "Norah Jones": 3.0, "Phoenix": 5.0,
                 "Slightly Stoopid": 4.0, "The Strokes": 5.0},

         "Veronica": {"Blues Traveler": 3.0, "Norah Jones": 5.0,
                      "Phoenix": 4.0, "Slightly Stoopid": 2.5,
                      "The Strokes": 3.0}
        }



class recommender:

    def __init__(self, data, k=1, metric='pearson', n=5):
        """ initialize recommender
        currently, if data is dictionary the recommender is initialized
        to it.
        For all other data types of data, no initialization occurs
        k is the k value for k nearest neighbor
        metric is which distance formula to use
        n is the maximum number of recommendations to make"""
        self.k = k
        self.n = n
        self.username2id = {}
        self.userid2name = {}
        self.productid2name = {}
        # for some reason I want to save the name of the metric
        self.metric = metric
        if self.metric == 'pearson':
            self.fn = self.pearson
        #
        # if data is dictionary set recommender data to it
        #
        if type(data).__name__ == 'dict':
            self.data = data

    def convertProductID2name(self, id):
        """Given product id number return product name"""
        if id in self.productid2name:
            return self.productid2name[id]
        else:
            return id


    def userRatings(self, id, n):
        """Return n top ratings for user with id"""
        print ("Ratings for " + self.userid2name[id])
        ratings = self.data[id]
        print(len(ratings))
        ratings = list(ratings.items())
        ratings = [(self.convertProductID2name(k), v)
                   for (k, v) in ratings]
        # finally sort and return
        ratings.sort(key=lambda artistTuple: artistTuple[1],
                     reverse = True)
        ratings = ratings[:n]
        for rating in ratings:
            print("%s\t%i" % (rating[0], rating[1]))




    def loadBookDB(self, path=''):
        """loads the BX book dataset. Path is where the BX files are
        located"""
        self.data = {}
        i = 0
        #
        # First load book ratings into self.data
        #
        f = codecs.open(path + "BX-Book-Ratings.csv", 'r', 'utf8')
        for line in f:
            i += 1
            #separate line into fields
            fields = line.split(';')
            user = fields[0].strip('"')
            book = fields[1].strip('"')
            rating = int(fields[2].strip().strip('"'))
            if user in self.data:
                currentRatings = self.data[user]
            else:
                currentRatings = {}
            currentRatings[book] = rating
            self.data[user] = currentRatings
        f.close()
        #
        # Now load books into self.productid2name
        # Books contains isbn, title, and author among other fields
        #
        f = codecs.open(path + "BX-Books.csv", 'r', 'utf8')
        for line in f:
            i += 1
            #separate line into fields
            fields = line.split(';')
            isbn = fields[0].strip('"')
            title = fields[1].strip('"')
            author = fields[2].strip().strip('"')
            title = title + ' by ' + author
            self.productid2name[isbn] = title
        f.close()
        #
        #  Now load user info into both self.userid2name and
        #  self.username2id
        #
        f = codecs.open(path + "BX-Users.csv", 'r', 'utf8')
        for line in f:
            i += 1
            #print(line)
            #separate line into fields
            fields = line.split(';')
            userid = fields[0].strip('"')
            location = fields[1].strip('"')
            if len(fields) > 3:
                age = fields[2].strip().strip('"')
            else:
                age = 'NULL'
            if age != 'NULL':
                value = location + '  (age: ' + age + ')'
            else:
                value = location
            self.userid2name[userid] = value
            self.username2id[location] = userid
        f.close()
        print(i)


    def pearson(self, rating1, rating2):
        sum_xy = 0
        sum_x = 0
        sum_y = 0
        sum_x2 = 0
        sum_y2 = 0
        n = 0
        for key in rating1:
            if key in rating2:
                n += 1
                x = rating1[key]
                y = rating2[key]
                sum_xy += x * y
                sum_x += x
                sum_y += y
                sum_x2 += pow(x, 2)
                sum_y2 += pow(y, 2)
        if n == 0:
            return 0
        # now compute denominator
        denominator = (sqrt(sum_x2 - pow(sum_x, 2) / n)
                       * sqrt(sum_y2 - pow(sum_y, 2) / n))
        if denominator == 0:
            return 0
        else:
            return (sum_xy - (sum_x * sum_y) / n) / denominator


    def computeNearestNeighbor(self, username):
        """creates a sorted list of users based on their distance to
        username"""
        distances = []
        for instance in self.data:
            if instance != username:
                distance = self.fn(self.data[username],
                                   self.data[instance])
                distances.append((instance, distance))
        # sort based on distance -- closest first
        distances.sort(key=lambda artistTuple: artistTuple[1],
                       reverse=True)
        return distances

    def recommend(self, user):
       """Give list of recommendations"""
       recommendations = {}
       # first get list of users  ordered by nearness
       nearest = self.computeNearestNeighbor(user)
       #
       # now get the ratings for the user
       #
       userRatings = self.data[user]
       #
       # determine the total distance
       totalDistance = 0.0
       for i in range(self.k):
          totalDistance += nearest[i][1]
       # now iterate through the k nearest neighbors
       # accumulating their ratings
       for i in range(self.k):
          # compute slice of pie 
          weight = nearest[i][1] / totalDistance
          # get the name of the person
          name = nearest[i][0]
          # get the ratings for this person
          neighborRatings = self.data[name]
          # get the name of the person
          # now find bands neighbor rated that user didn't
          for artist in neighborRatings:
             if not artist in userRatings:
                if artist not in recommendations:
                   recommendations[artist] = (neighborRatings[artist]
                                              * weight)
                else:
                   recommendations[artist] = (recommendations[artist]
                                              + neighborRatings[artist]
                                              * weight)
       # now make list from dictionary
       recommendations = list(recommendations.items())
       recommendations = [(self.convertProductID2name(k), v)
                          for (k, v) in recommendations]
       # finally sort and return
       recommendations.sort(key=lambda artistTuple: artistTuple[1],
                            reverse = True)
       # Return the first n items
       return recommendations[:self.n]

r = recommender(users)
# The author implementation
r.loadBookDB('/Users/mona/Downloads/BX-Dump/')

ratings = pd.read_csv('/Users/danialt/BX-CSV-Dump/BX-Book-Ratings.csv', sep=";", quotechar="\"", escapechar="\\")
books = pd.read_csv('/Users/danialt/BX-CSV-Dump/BX-Books.csv', sep=";", quotechar="\"", escapechar="\\")
users = pd.read_csv('/Users/danialt/BX-CSV-Dump/BX-Users.csv', sep=";", quotechar="\"", escapechar="\\")



pivot_rating = ratings.pivot(index='User-ID', columns='ISBN', values='Book-Rating')

回答 0

在Ubuntu上,您可能需要先安装软件包管理器pip

sudo apt-get install python-pip

然后使用以下命令安装python-dateutil软件包:

sudo pip install python-dateutil

On Ubuntu you may need to install the package manager pip first:

sudo apt-get install python-pip

Then install the python-dateutil package with:

sudo pip install python-dateutil

回答 1

您可以在https://pypi.python.org/pypi/python-dateutil中找到dateutil包。将其解压缩到某个地方并运行命令:

python setup.py install

它为我工作!

You can find the dateutil package at https://pypi.python.org/pypi/python-dateutil. Extract it to somewhere and run the command:

python setup.py install

It worked for me!


回答 2

对于Python 3:

pip3 install python-dateutil

For Python 3:

pip3 install python-dateutil

回答 3

对于上述Python 3,请使用:

sudo apt-get install python3-dateutil

For Python 3 above, use:

sudo apt-get install python3-dateutil

回答 4

如果使用的是virtualenv,请确保从virtualenv内部运行pip 。

$ which pip
/Library/Frameworks/Python.framework/Versions/Current/bin/pip
$ find . -name pip -print
./flask/bin/pip
./flask/lib/python2.7/site-packages/pip
$ ./flask/bin/pip install python-dateutil

If you’re using a virtualenv, make sure that you are running pip from within the virtualenv.

$ which pip
/Library/Frameworks/Python.framework/Versions/Current/bin/pip
$ find . -name pip -print
./flask/bin/pip
./flask/lib/python2.7/site-packages/pip
$ ./flask/bin/pip install python-dateutil

回答 5

没有一种解决方案对我有用。如果您使用的是PIP,请执行以下操作:

pip install pycrypto==2.6.1

None of the solutions worked for me. If you are using PIP do:

pip install pycrypto==2.6.1


回答 6

在适用于Python2的Ubuntu 18.04中:

sudo apt-get install python-dateutil

In Ubuntu 18.04 for Python2:

sudo apt-get install python-dateutil

回答 7

我在MacOS上也遇到了同样的问题,尝试安装python-dateutil对我来说是有用的

i have same issues on my MacOS and it’s work for me to try install python-dateutil


回答 8

如果您使用Pipenv,则可能需要将此添加到您的Pipfile

[packages]
python-dateutil = "*"

If you are using Pipenv, you may need to add this to your Pipfile:

[packages]
python-dateutil = "*"

Mac OS X 10.9之后无法安装PIL

问题:Mac OS X 10.9之后无法安装PIL

我刚刚将Mac OS更新为10.9,发现其中的某些(全部?)Python模块不再可用,尤其是Image模块。

所以我尝试执行sudo pip install pil,但是出现此错误:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found

#      include <X11/Xlib.h>

               ^

1 error generated.

error: command 'cc' failed with exit status 1

我的Xcode是最新的,我不知道。PIL可能还不兼容10.9吗?

I’ve just updated my Mac OS to 10.9 and I discovered that some (all?) of my Python modules are not here anymore, especially the Image one.

So I try to execute sudo pip install pil, but I get this error:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found

#      include <X11/Xlib.h>

               ^

1 error generated.

error: command 'cc' failed with exit status 1

My Xcode is up-to-date and I don’t have any idea. Is it possible that PIL is not yet 10.9 compatible ?


回答 0

以下为我工作:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
sudo pip install pil

更新:

但是,威尔提供了以下更正确的解决方案。

打开终端并执行: xcode-select --install

Following worked for me:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
sudo pip install pil

UPDATE:

But there is more correct solution below, provided by Will.

open your terminal and execute: xcode-select --install


回答 1

打开终端并执行:

xcode-select --install

open your terminal and execute:

xcode-select --install


回答 2

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/ /usr/local/include/X11

对我有帮助!操作系统x 10.9

pip install pillow

但!点安装后…

*** ZLIB (PNG/ZIP) support not available

最后我通过运行来修复它:

xcode-select --install

然后重新安装枕头

pip install pillow

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.2.1
    platform     darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
                 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
    --------------------------------------------------------------------
    --- TKINTER support available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- TIFF G3/G4 (experimental) support available
    --- FREETYPE2 support available
    --- LITTLECMS support available
    --- WEBP support available
    --- WEBPMUX support available
    --------------------------------------------------------------------
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/ /usr/local/include/X11

helps for me! os x 10.9

pip install pillow

but! after pip install …

*** ZLIB (PNG/ZIP) support not available

and finally i fix it by running:

xcode-select --install

then reinstall pillow

pip install pillow

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.2.1
    platform     darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
                 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
    --------------------------------------------------------------------
    --- TKINTER support available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- TIFF G3/G4 (experimental) support available
    --- FREETYPE2 support available
    --- LITTLECMS support available
    --- WEBP support available
    --- WEBPMUX support available
    --------------------------------------------------------------------

回答 3

适用于我(OS X Yosemite 10.10.2-Python 2.7.9):

xcode-select --install
sudo pip install pillow

尝试检查一下:

from PIL import Image
image = Image.open("file.jpg")
image.show()

Works for me ( OS X Yosemite 10.10.2 – Python 2.7.9 ) :

xcode-select --install
sudo pip install pillow

Try this to check it:

from PIL import Image
image = Image.open("file.jpg")
image.show()

回答 4

这是我所做的,某些步骤可能仅对于PIL并不是必需的,但无论如何我都需要libpng和其他步骤:

1)运行xcode install,使用此命令或从应用商店下载更新:

xcode-select --install

1b)添加命令行工具可选工具,在Mountain Lion中,这是xcode下载页面上的一个选项,但是现在您必须注册您的Apple ID并从以下位置下载: https //developer.apple.com/downloads/

寻找Xcode的命令行工具(OS X Mavericks)

2)安装python所需的一切(使用brew),我相信您也可以使用port:

brew install readline sqlite gdbm
brew install python --universal --framework 
brew install libpng jpeg freetype

必要时取消链接/重新链接,即升级。

3)安装Pip和所需的模块:

easy_install pip 
sudo pip install setuptools --no-use-wheel --upgrade

4)最后,这没有错误:

sudo pip install Pillow

2014年11月4日更新:PIL存储区不再收到更新或支持,因此应使用Pillow。现在不建议使用以下内容,因此请坚持使用Pillow。

sudo pip install pil --allow-external pil --allow-unverified pil

UPDATE(旧):安装Pillow(PIL拨叉)时同样适用,并且在大多数情况下,它很快就可以替代PILlow。而不是在步骤4中安装pip,而是运行以下命令:

sudo pip install Pillow

希望这对某人有帮助!

Here is what I did, some steps may not be necessary just for PIL but I needed libpng and others anyways:

1) Run xcode install, use this command or download updates from the app store:

xcode-select --install

1b) Add the Command Line Tools optional tool, in Mountain Lion this was an option on the xcode Download page, but now you have to register with your apple id and download from: https://developer.apple.com/downloads/

Look for Command Line Tools (OS X Mavericks) for Xcode

2) Install everything needed for python (using brew), I believe you can use port as well:

brew install readline sqlite gdbm
brew install python --universal --framework 
brew install libpng jpeg freetype

Unlink/ relink if needed i.e. if upgrading.

3) Install Pip and required modules:

easy_install pip 
sudo pip install setuptools --no-use-wheel --upgrade

4) Finally this works with no errors:

sudo pip install Pillow

UPDATE 11/04/14: PIL repo no longer receives updates or support so Pillow should be used. The below is now deprecated so stick with Pillow.

sudo pip install pil --allow-external pil --allow-unverified pil

UPDATE (OLD) : The same thing applies when installing Pillow (PIL fork) and should be mentioned as its quickly becoming a replacement in most cases of PIL. Instead of installing pip in step 4, run this instead:

sudo pip install Pillow

Hope this helps someone!


回答 5

安装命令行工具为我解决了这个问题

您必须分别安装它们,因为它们现在不属于xcode软件包中的一部分:

https://developer.apple.com/downloads/index.action?=command%20line%20tools#

installing command line tools fixed the issue for me

you have to install them separately as they are not part of the packages in xcode now:

https://developer.apple.com/downloads/index.action?=command%20line%20tools#


回答 6

这些都不对我有用。我一直收到:

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1

因此,我找到了以下解决方案:

sudo export CFLAGS=-Qunused-arguments
sudo export CPPFLAGS=-Qunused-arguments
sudo pip install PIL --allow-external PIL --allow-unverified PIL

这样我就可以安装。

Non of those worked for me.. I kept receiving:

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1

So I found a work around with the following solution:

sudo export CFLAGS=-Qunused-arguments
sudo export CPPFLAGS=-Qunused-arguments
sudo pip install PIL --allow-external PIL --allow-unverified PIL

This way I was able to install.


回答 7

我有一个类似的问题:安装枕头失败clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future],安装枕头失败Can't install the software because it is not currently available from the Software Update server.,并且,即使手动安装了命令行工具,PIL的编译也失败了。

发生这种情况是因为最新版本的xcode下的clang不会警告未知的编译器标志,而是通过硬错误停止编译。

要解决此问题,只需export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"在终端上运行,然后再尝试进行编译(安装pil)。

I had a similar problem: Installing pillow failed with clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future], installing command line tools failed with Can't install the software because it is not currently available from the Software Update server., and even after installing the command line tools manually, the compilation of PIL failed.

This happens cause clang under the newest version of xcode doesn’t warn on unknown compiler flags, but rather stop the compilation with a hard error.

To fix this, just run export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" on the terminal before trying to compile (installing pil).


回答 8

只需运行

pip install pil --allow-external pil --allow-unverified pil

Simply run

pip install pil --allow-external pil --allow-unverified pil


回答 9

这是我在Mac OS 10.9.1上的步骤

1. sudo su
2. easy_install pip
3. xcode-select --install
4. pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

This my steps on mac os 10.9.1

1. sudo su
2. easy_install pip
3. xcode-select --install
4. pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

回答 10

您可以使用Homebrew进行安装 http://brew.sh

brew tap Homebrew/python
brew install pillow

You could use Homebrew to do the install http://brew.sh

brew tap Homebrew/python
brew install pillow

回答 11

确保在xcode上安装了命令行工具。然后执行:

sudo pip install pil --allow-external pil --allow-unverified pil

Make sure you have Command Line Tools installed on your xcode. Then execute:

sudo pip install pil --allow-external pil --allow-unverified pil

回答 12

我遇到以下错误

building 'PIL._imagingft' extension
_imagingft.c:62:10: fatal error: 'freetype/fterrors.h' file not found

#include <freetype/fterrors.h>

         ^

1 error generated.

error: command 'cc' failed with exit status 1

解决方案是将freetype2符号链接到freetype,从而解决了该问题。

I was having the following error

building 'PIL._imagingft' extension
_imagingft.c:62:10: fatal error: 'freetype/fterrors.h' file not found

#include <freetype/fterrors.h>

         ^

1 error generated.

error: command 'cc' failed with exit status 1

The solution to this was to symlink freetype2 to freetype and this solved the problem.


回答 13

我不想安装XCode(我不使用它),但我讨厌摆弄Application目录。我从这篇文章的许多答案中脱颖而出,以下两个步骤对我来说适用于10.9.5:

sudo easy_install pip
sudo pip install pillow

我不得不使用easy_install来安装pip确实让我感到奇怪。但是pip不想在重新安装之前为我工作。

I didn’t want to install XCode (I don’t use it) and I’m loath to fiddle with Application directory. I’ve cribbed from the many answers in this post and the following two steps work for me with 10.9.5:

sudo easy_install pip
sudo pip install pillow

It did appear to me strange that I had to use easy_install to install pip. But pip didn’t want to work for me before that (re-)install.


回答 14

找到了解决方案…您必须像这样对X11进行符号链接ln -s /opt/X11/include/X11 /usr/local/include/X11,然后sudo pip install pil才能正常工作。

Found the solution … You’ve to symlink X11 like this ln -s /opt/X11/include/X11 /usr/local/include/X11 and then sudo pip install pil should work.


回答 15

重用@DmitryDemidenko的答案对我有用:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11

然后

sudo pip install -U PIL --allow-external PIL --allow-unverified PIL

Reusing @DmitryDemidenko’s answer that is how it worked for me:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11

and then

sudo pip install -U PIL --allow-external PIL --allow-unverified PIL

回答 16

执行下面的命令行。在Mac OS 10.9.5上像超级按钮一样工作

easy_install点

sudo pip install setuptools –no-use-wheel –upgrade

sudo pip安装枕头

最好的,西奥

Execute the bellow command lines. Works like a charm on Mac OS 10.9.5

easy_install pip

sudo pip install setuptools –no-use-wheel –upgrade

sudo pip install Pillow

Best, Theo


回答 17

那就是我所做的:

首先升级到Xcode 5(我正在运行10.9)。然后,在终端中执行以下命令:

$ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 usr/include/

That’s what I did:

First upgrade to Xcode 5 (I am running 10.9). Then, execute the following commands in a terminal:

$ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 usr/include/

回答 18

一个更完整的解决方案需要安装Xquartz X11子系统,该子系统已经在Apple之外构建了几年。这是我用来使其全部工作的步骤

  1. http://xquartz.macosforge.org/landing/安装XQuartz
  2. sudo pip install pillow

A more complete solution requires the installation of the Xquartz X11 subsystem that has been built outside of Apple for several years now. Here are the steps I used to get it all working

  1. Install XQuartz from http://xquartz.macosforge.org/landing/
  2. Run sudo pip install pillow

回答 19

因为公认的答案是正确的答案,xcode-select --install但有些人(包括我)可能会遇到Can't install the software because it is not currently available from the Software Update server 如果您使用的是Beta版软件(因为我现在使用的是优胜美地并且遇到相同的问题),则您需要单独购买CLT,因为它不包含在其中。 XCode(甚至xcode beta)也可以转到developers.apple.com并为您的OS获取CLT工具;)

PS您不需要XQuartz的PIL或Pillow即可工作

As the accepted answer is the right one with xcode-select --install but some people (including me) may encounter Can't install the software because it is not currently available from the Software Update server If you are using beta software (as I am using Yosemite now and had the same problem) you NEED to get the CLT separately since it is NOT included in XCode (even xcode beta) Head over to developers.apple.com and get CLT tools for your OS ;)

P.S. You don’t need XQuartz for PIL or Pillow to work


回答 20

我最近从OS 10.8-> 10.9升级的机器陷入了xcrun和lipo之间的循环。

将/ usr / bin / lipo重命名为/ usr / bin / lipo_broken

请参阅此线程以获取有关如何解决的更多信息:

使用OS X Mavericks和XCode 4.x冻结xcrun / lipo

My machine which was recently upgraded from OS 10.8 -> 10.9 got stuck in a loop between xcrun and lipo.

Rename /usr/bin/lipo to /usr/bin/lipo_broken

Refer to this thread for further information on how to resolve:

xcrun/lipo freezes with OS X Mavericks and XCode 4.x


回答 21

改为安装枕头

sudo pip install pillow

Install Pillow instead:

sudo pip install pillow

回答 22

ln -s /usr/local/include/freetype2 /usr/local/include/freetype
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pil
ln -s /usr/local/include/freetype2 /usr/local/include/freetype
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pil

回答 23

试试这个:

ln -s /usr/local/include/freetype2 /usr/local/include/freetype

Try this:

ln -s /usr/local/include/freetype2 /usr/local/include/freetype

回答 24

sudo pip uninstall pillow
pip install pillow

为我工作。我在优胜美地上运行Python 2.7.9。import PIL现在为我工作。

sudo pip uninstall pillow
pip install pillow

worked for me. I’m running Python 2.7.9 on Yosemite.import PIL now works for me.


回答 25

在Mac OSC 10.10 Yosemite上安装PIL(Imaging.1.1.7)。我尝试了这里推荐的许多修复程序,但是每个修复程序都遇到了麻烦。我终于通过编辑setup.py文件来解决了这个问题:

TCL_ROOT =“ / opt / X11 / include”

它在_imagingtk.c的编译中通过了X11的适当包含路径,这对我造成了问题。更改后立即工作。

Installing PIL (Imaging.1.1.7) on Mac OSC 10.10 Yosemite. I tried numerous fixes recommended here but ran into trouble with each one. I finally solved this problem by editing the setup.py file such that:

TCL_ROOT = “/opt/X11/include”

which passes the appropriate include path for X11 in the compilation of _imagingtk.c, which was causing the problem for me. Worked immediately after change.


回答 26

我已从pyenv移至virtualenv,这解决了我的问题。

I’ve moved from pyenv to virtualenv and this fixed my problem.


回答 27

  1. ln -s / opt / X11 / include / X11 / usr / local / include / X11
  2. 没有sudo的pip install pil
  1. ln -s /opt/X11/include/X11 /usr/local/include/X11
  2. pip install pil without sudo

如何使用Pipfile和Pipfile.lock?

问题:如何使用Pipfile和Pipfile.lock?

在Python封装的上下文中,似乎Pipfile / Pipfile.lock旨在替代Requirements.txt。但是,关于它们如何实际工作的文献很少。我在这里的Python网站的PyPi部分找到了对pipfile的不断发展的描述,但这很混乱,并且没有解释文件不同部分的语义。

关于如何理解这些文件的任何指示?

It seems that Pipfile/Pipfile.lock are intended to be replacements for requirements.txt, in the context of Python packaging. There isn’t much documentation out there on how these actually work, however. I found an evolving description of pipfile on the PyPi section of the Python website here but it’s pretty messy and doesn’t explain the semantics of the different sections of the file.

Any pointers on how to understand these files?


回答 0

如果您对Ruby的Bundler或Node的Npm有一定的了解,这些文件的概念很简单,并且与其他现有工具类似。Pipenv是使用Pipfile和Pipfile.lock文件实现这些目标的程序包和虚拟环境管理工具。

Pipenv以一种默认的标准方式为您处理虚拟环境(不再需要激活和停用)。下面是一些入门的基础知识,请在pipenv网站上查看更多信息

入门

在您的项目文件夹类型中,开始使用pipenv很容易。

$ pipenv install

…,如果已经有一个requirements.txt文件,它将生成一个Pipfile带有需求的文件和一个虚拟环境文件夹,否则,它将生成一个空Pipfile文件。如果您不喜欢或改变主意,请输入…

$ pipenv uninstall <package>

…而且您很高兴。要激活已生成pipenv的虚拟环境,请继续…

$ pipenv shell

…,您的虚拟环境将被激活。离开环境…

$ exit

…,您将回到原来的终端会话。

点文件

Pipfile文件旨在指定套餐要求为您的Python应用程序或库,既要发展和执行。您只需使用…即可安装软件包。

$ pipenv install flask

…并将其添加为部署和执行的依赖项或使用…

$ pipenv install --dev pytest

…,它将用作开发时间的依赖。文件语法非常简单,如下所示。

[[source]] # Here goes your package sources (where you are downloading your packages from).
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages] # Here goes your package requirements for running the application and its versions (which packages you will use when running the application).
requests = "*"
flask = "*"
pandas = "*"

[dev-packages] # Here goes your package requirements for developing the application and its versions (which packaes you will use when developing the application)
pylint = "*"
wheel = "*"

[requires] # Here goes your required Python version.
python_version = "3.6"

Pipfile.lock

Pipfile.lock是用来规定的基础上,目前在包装Pipfile,应使用哪个那些特定版本,避免自动升级依赖于对方的包和破坏你的项目的依赖关系树的风险。

您可以使用…锁定当前安装的软件包。

$ pipenv lock

…,然后该工具将根据当前安装的版本查找您的虚拟环境文件夹,以自动为您生成锁定文件。文件语法并不像Pipfile那样明显,因此为简洁起见,此处不会显示。

The concept behind these files is simple and analogue to other already existing tools, if you have some familiarity with Ruby’s Bundler or Node’s Npm. Pipenv is both a package and virtual environment management tool that uses the Pipfile and Pipfile.lock files to achieve these goals.

Pipenv handles the virtual environment for you in one default standard way (no more activate and deactivate required). Below, some basics to get you started, see more at pipenv website.

Getting Started

Start using pipenv is easy, in your project folder type…

$ pipenv install

… and if it already has a requirements.txt file, it will generate a Pipfile file with the requirements and a virtual environment folder, otherwise, it will generate an empty Pipfile file. If you disliked or changed your mind about something that you have installed, just type…

$ pipenv uninstall <package>

… and you’re good to go. To activate the virtual environment that pipenv already generated, go with…

$ pipenv shell

… and your virtual environment will be activated. To leave the environment…

$ exit

… and you will be back to your original terminal session.

Pipfile

The Pipfile file is intended to specify packages requirements for your Python application or library, both to development and execution. You can install a package by simply using…

$ pipenv install flask

… and it will be added as a dependency for deployment and execution or by using …

$ pipenv install --dev pytest

… and it will be used as a depencency for development time. The file syntax is pretty straight forward, as follows.

[[source]] # Here goes your package sources (where you are downloading your packages from).
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages] # Here goes your package requirements for running the application and its versions (which packages you will use when running the application).
requests = "*"
flask = "*"
pandas = "*"

[dev-packages] # Here goes your package requirements for developing the application and its versions (which packaes you will use when developing the application)
pylint = "*"
wheel = "*"

[requires] # Here goes your required Python version.
python_version = "3.6"

Pipfile.lock

The Pipfile.lock is intended to specify, based on the packages present in Pipfile, which specific version of those should be used, avoiding the risks of automatically upgrading packages that depend upon each other and breaking your project dependency tree.

You can lock your currently installed packages using…

$ pipenv lock

… and the tool will lookup your virtual environment folder to generate the lock file for you automatically, based on the currently installed versions. The file syntax is not as obvious as is for Pipfile , so for the sake of conciseness, it will not be displayed here.


如何在Mac OS X上为Python 3安装pip?

问题:如何在Mac OS X上为Python 3安装pip?

OS X(Mavericks)已安装Python 2.7库存。但是我用3.3来做我自己的所有Python个人资料。我刚刚冲洗了3.3.2安装并安装了新的3.3.3。所以我需要pyserial再次安装。我可以按照以前做过的方式来做,即:

  1. 从pypi下载pyserial
  2. 解压pyserial.tgz
  3. cd pyserial
  4. python3 setup.py install

但是我想像酷孩子一样做,并且做类似的事情pip3 install pyserial。但目前尚不清楚我如何达到目标。就这一点。对virtualenv不感兴趣(除非必须如此)。

OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I’ve done it before, which is:

  1. Download pyserial from pypi
  2. untar pyserial.tgz
  3. cd pyserial
  4. python3 setup.py install

But I’d like to do like the cool kids do, and just do something like pip3 install pyserial. But it’s not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet.


回答 0

更新:Python3.4不再需要此功能。它会在库存安装中安装pip3。

我最终在python邮件列表上发布了相同的问题,并得到以下答案:

# download and install setuptools
curl -O https://bootstrap.pypa.io/ez_setup.py
python3 ez_setup.py
# download and install pip
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

完美解决了我的问题。在为我自己添加以下内容之后:

cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip

为了能够直接运行pip,我能够:

# use pip to install
pip install pyserial

要么:

# Don't want it?
pip uninstall pyserial

UPDATE: This is no longer necessary with Python3.4. It installs pip3 as part of the stock install.

I ended up posting this same question on the python mailing list, and got the following answer:

# download and install setuptools
curl -O https://bootstrap.pypa.io/ez_setup.py
python3 ez_setup.py
# download and install pip
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

Which solved my question perfectly. After adding the following for my own:

cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip

So that I could run pip directly, I was able to:

# use pip to install
pip install pyserial

or:

# Don't want it?
pip uninstall pyserial

回答 1

我必须自己经历这个过程,并选择一种从长远来看更好的方法。

我安装了自制软件

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后:

brew doctor

最后一步为您提供一些必须解决的警告和错误。其中之一将是下载并安装Mac OS X命令行工具

然后:

brew install python3

这给了我,python3并且走pip3了我的路。

pieter$ which pip3 python3
/usr/local/bin/pip3
/usr/local/bin/python3

I had to go through this process myself and chose a different way that I think is better in the long run.

I installed homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

then:

brew doctor

The last step gives you some warnings and errors that you have to resolve. One of those will be to download and install the Mac OS X command-line tools.

then:

brew install python3

This gave me python3 and pip3 in my path.

pieter$ which pip3 python3
/usr/local/bin/pip3
/usr/local/bin/python3

回答 2

在Mac上安装Python3

1. brew install python3
2. curl https://bootstrap.pypa.io/get-pip.py | python3
3. python3

使用pip3安装模块

1. pip3 install ipython
2. python3 -m IPython

:)

Install Python3 on mac

1. brew install python3
2. curl https://bootstrap.pypa.io/get-pip.py | python3
3. python3

Use pip3 to install modules

1. pip3 install ipython
2. python3 -m IPython

:)


回答 3

另外:当您使用python3安装请求时,命令为:

pip3 install requests

pip install requests

Plus: when you install requests with python3, the command is:

pip3 install requests

not

pip install requests

回答 4

  1. brew install python3
  2. 在您的外壳配置文件中创建别名

    • 例如。alias pip3="python3 -m pip"在我的.zshrc

➜〜pip3-版本

来自/usr/local/lib/python3.6/site-packages(python 3.6)的pip 9.0.1

  1. brew install python3
  2. create alias in your shell profile

    • eg. alias pip3="python3 -m pip" in my .zshrc

➜ ~ pip3 –version

pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)


回答 5

这是我的简单解决方案:

如果您的系统中同时安装了python2和python3,则默认情况下pip升级将指向python2。因此,我们必须指定python(python3)的版本并使用以下命令:

python3 -m pip install --upgrade pip

此命令将卸载以前安装的pip并安装新版本-升级pip。

这将节省内存并使系统混乱。

图像-在MacOS上如何在Python3中升级pip

Here is my simple solution:

If you have python2 and python3 both installed in your system, the pip upgrade will point to python2 by default. Hence, we must specify the version of python(python3) and use the below command:

python3 -m pip install --upgrade pip

This command will uninstall the previously installed pip and install the new version- upgrading your pip.

This will save memory and declutter your system.

Image – How the upgrading of pip in Python3 works on MacOS


回答 6

要使用Python EasyInstall(我想您要使用它)非常简单!

sudo easy_install pip

因此,然后使用pip安装Pyserial,您可以执行以下操作:

pip install pyserial

To use Python EasyInstall (which is what I think you’re wanting to use), is super easy!

sudo easy_install pip

so then with pip to install Pyserial you would do:

pip install pyserial

回答 7

另外,值得一提的是Max OSX / macOS用户可以使用 Homebrew安装pip3。

$> brew update
$> brew install python3
$> pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

Also, it’s worth to mention that Max OSX/macOS users can just use Homebrew to install pip3.

$> brew update
$> brew install python3
$> pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

回答 8

Mac OS X Mojave python代表的2.7版本,Python和python3为版本3.同样是Pythonpippip3。所以,要升级pippython 3做到这一点:

~$ sudo pip3 install --upgrade pip

On Mac OS X Mojave python stands for python of version 2.7 and python3 for python of version 3. The same is pip and pip3. So, to upgrade pip for python 3 do this:

~$ sudo pip3 install --upgrade pip

回答 9

在MacOS 10.12上

下载点数:pip asget-pip.py

下载python3:python3

  1. 安装python3
  2. 打开终端: python3 get-pip.py
  3. pip3 可用

On MacOS 10.12

download pip: pip as get-pip.py

download python3: python3

  1. install python3
  2. open terminal: python3 get-pip.py
  3. pip3 is available

回答 10

pip 使用brew通过python2自动安装:

  1. brew install python3
  2. pip3 --version

pip is installed automatically with python2 using brew:

  1. brew install python3
  2. pip3 --version

回答 11

如果您的Mac上未安装pip,则只需在终端上运行以下命令即可。

sudo easy_install pip

在此处下载python 3: python3

完成这两个步骤后,请确保运行以下命令以验证是否已成功安装它们。

python3 --version
pip3 --version

simply run following on terminal if you don’t have pip installed on your mac.

sudo easy_install pip

download python 3 here: python3

once you’re done with these 2 steps, make sure to run the following to verify whether you’ve installed them successfully.

python3 --version
pip3 --version

回答 12

对于全新的Mac,您需要执行以下步骤:-

  1. 确保已安装 Xcode
  2. sudo easy_install pip
  3. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  4. brew doctor
  5. brew doctor
  6. brew install python3

完成后,只需python3在终端上键入,就会看到安装了python 3。

For a fresh new Mac, you need to follow below steps:-

  1. Make sure you have installed Xcode
  2. sudo easy_install pip
  3. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  4. brew doctor
  5. brew doctor
  6. brew install python3

And you are done, just type python3 on terminal and you will see python 3 installed.


回答 13

我在python3和pip3中遇到了同样的问题。决策:使用链接和其他东西解决所有冲突

brew doctor

之后

brew reinstall python3

I had the same problem with python3 and pip3. Decision: solving all conflicts with links and other stuff when do

brew doctor

After that

brew reinstall python3

pip安装后,virtualenvwrapper.sh在哪里?

问题:pip安装后,virtualenvwrapper.sh在哪里?

我正在尝试在OSX上设置virtualenvwrapper,发现的所有说明和教程都告诉我向.profile添加源命令,指向virtualenvwrapper.sh。我已经检查了所有的python和site-packages目录,但找不到任何virtualenvwrapper.sh。这是我需要单独下载的东西吗?pip安装不正确吗?

这是/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenvwrapper的内容:

hook_loader.py      hook_loader.pyc     project.py      project.pyc     user_scripts.py     user_scripts.pyc

如您所见,没有virtualenvwrapper.sh。它在哪里?

I’m trying to setup virtualenvwrapper on OSX, and all the instructions and tutorials I’ve found tell me to add a source command to .profile, pointing towards virtualenvwrapper.sh. I’ve checked all the python and site-packages directories, and I can’t find any virtualenvwrapper.sh. Is this something I need to download separately? Is pip not installing correctly?

This is the contents of /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenvwrapper:

hook_loader.py      hook_loader.pyc     project.py      project.pyc     user_scripts.py     user_scripts.pyc

As you can see, no virtualenvwrapper.sh. Where is it?


回答 0

您可以使用以下find命令搜索文件:

find / -name virtualenvwrapper.sh

这将从根目录的所有目录中搜索该文件。


在ubuntu 12.04 LTS上,通过pip安装,它已安装到

/usr/local/bin/virtualenvwrapper.sh


在ubuntu 17.04上,以pip身份作为普通用户安装,它已安装到

~/.local/bin/virtualenvwrapper.sh

You can use the find command to search for a file:

find / -name virtualenvwrapper.sh

This will search all directories from the root for the file.


on ubuntu 12.04 LTS, installing through pip, it is installed to

/usr/local/bin/virtualenvwrapper.sh


on ubuntu 17.04, installing through pip as a normal user, it is installed to

~/.local/bin/virtualenvwrapper.sh


回答 1

您已经尝试过吗?

$ which virtualenvwrapper.sh

did you already try this ?

$ which virtualenvwrapper.sh

回答 2

我只是用pip重新安装了它。

sudo pip uninstall virtualenvwrapper
sudo pip install virtualenvwrapper

这次将其放在/ usr / local / bin中。

I just reinstalled it with pip.

sudo pip uninstall virtualenvwrapper
sudo pip install virtualenvwrapper

And this time it put it in /usr/local/bin.


回答 3

各个OS所存储/定位的virtualenvwrapper.sh 的确切路径 有所不同。即使在相同的操作系统中,它也因版本而异因此,我们需要适用于所有OS版本的通用解决方案。

我找到其路径的最简单方法是

pip uninstall virtualenvwrapper

这将提示您进行确认。说“否”,但确认的第一行显示virtualenvwrapper.sh的路径(提示提供了将删除的文件列表,如果您说是的话。此列表中的第一项包含您计算机中virtualenvwrapper.sh的路径)

The exact path where virtualenvwrapper.sh is stored/located varies from OS to OS. Even with in same OS, it varies from version to version. So we need a generic solution that works for all OS versions.

Easiest way I have found to find its path is: Do

pip uninstall virtualenvwrapper

This will prompt a confirmation. Say “No” But first line of confirmation shows the path of virtualenvwrapper.sh (Prompt gives a list of files it will delete, if you say Yes. First entry in this list contains path to virtualenvwrapper.sh in your machine)


回答 4

或者像我一样..只需卸载virtualenvwrapper

sudo pip卸载virtualenvwrapper

然后使用easy_install进行安装

sudo easy_install virtualenvwrapper

这次我发现已安装文件“ /usr/local/bin/virtualenvwrapper.sh ” …在此之前,即使通过此命令我也找不到任何位置的文件

查找/ -name virtualenvwrapper.sh

or, like I did..just uninstall virtualenvwrapper

sudo pip uninstall virtualenvwrapper

and then install it with easy_install

sudo easy_install virtualenvwrapper

this time I found the file “/usr/local/bin/virtualenvwrapper.sh” installed… Before that I weren’t finding that file anywhere even by this command

find / -name virtualenvwrapper.sh


回答 5

在Mac OS上

which virtualenvwrapper.sh

你懂得

/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh

而且你可以

sudo ln /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh

在你的 .bash_profile

source /usr/local/bin/virtualenvwrapper.sh

或者你可以

source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh

On Mac OS

which virtualenvwrapper.sh

u got

/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh

and u can

sudo ln /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh

and in your .bash_profile

source /usr/local/bin/virtualenvwrapper.sh

or u can

source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh

回答 6

在OS X 10.8.2中,使用Python 2.7:

/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh

In OS X 10.8.2, with Python 2.7:

/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh


回答 7

在OSx EI机长中,我将virtualenvwrapper安装为

sudo pip3 install virtualenvwrapper

,但是我在中找不到virtualenvwrapper.sh /user/local/bin,它终于在找到了/Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper.sh,您可以通过以下方式建立到/ usr / local / bin的软链接:

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh,您可以按照官方文档的说明按照安装指南进行操作。祝好运!

In OSx EI captain, I installed the virtualenvwrapper as

sudo pip3 install virtualenvwrapper

, however I cannot find the virtualenvwrapper.sh in /user/local/bin, it was finally found at /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper.sh , and you can make an soft link to /usr/local/bin as

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh, and everything you can just follow the setup guide as the official document does. Good luck!


回答 8

对我来说是:

~/Library/Python/2.7/bin/virtualenvwrapper.sh

(对于OS X,带有pip install --user安装)

For me it was in :

~/Library/Python/2.7/bin/virtualenvwrapper.sh

(With OS X, with a pip install --user installation)


回答 9

我也有同样的问题。如果您使用的是virtualenvwrapper的旧版本,则pip无法正常工作。

http://pypi.python.org/pypi/virtualenvwrapper/3.6 和python setup.py安装文件下载src 。然后问题解决了。

I have the same problem. If you have older version of virtualenvwrapper, then pip wont work.

download src from http://pypi.python.org/pypi/virtualenvwrapper/3.6 and python setup.py install. Then the problem solved.


回答 10

对于基于RPM的发行版(如Fedora 19),运行sudo pip install virtualenvwrapper命令后,您可以在以下位置找到文件:

/usr/bin/virtualenvwrapper.sh

For RPM-based distributions(like Fedora 19), after running the sudo pip install virtualenvwrapper command, you may find the file at:

/usr/bin/virtualenvwrapper.sh

回答 11

使用普通用户在Ubuntu 15.10上使用pip安装了它,并~/.local/bin/virtualenvwrapper.sh通过运行找到了它:

$ find / -name virtualenvwrapper.sh 2>/dev/null

Installed it using pip on Ubuntu 15.10 using a normal user, it was put in ~/.local/bin/virtualenvwrapper.sh which I found by running:

$ find / -name virtualenvwrapper.sh 2>/dev/null


回答 12

使用

find / -name virtualenvwrapper.sh

我收到大量“拒绝权限”的信息,并且只有一个文件位置的打印输出。我错过了它,直到我用pip再次卸载/安装该文件时找到了该文件位置。

万一你好奇,那是在

/usr/local/share/python/virtualenvwrapper.sh

Using

find / -name virtualenvwrapper.sh

I got a TON of “permissions denied”s, and exactly one printout of the file location. I missed it until I found that file location when I uninstall/installed it again with pip.

In case you were curious, it was in

/usr/local/share/python/virtualenvwrapper.sh

回答 13

就我而言(OSX El Capitan,版本10.11.5),我需要按如下方式编辑.profile:

在终端中:

vim〜/ .profile

export WORKON_HOME=$HOME/.virtualenvs
export MSYS_HOME=C:\msys\1.0
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh                                                                                   

然后重新加载配置文件(它将在当前会话中可用。)

来源〜/ .profile

希望它会帮助某人。

In my case (OSX El Capitan, version 10.11.5) I needed to edit the .profile like so:

In the terminal:

vim ~/.profile

export WORKON_HOME=$HOME/.virtualenvs
export MSYS_HOME=C:\msys\1.0
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh                                                                                   

And then reload the profile (that it will be availuble in the current session.)

source ~/.profile

Hope it will help someone.


回答 14

我在玩virtualenvwrapper-4.8.4时可以在macOS Mojave(10.14)中找到一个

/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh

I can find one in macOS Mojave (10.14) while playing with virtualenvwrapper-4.8.4

/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh


回答 15

尽管这是OS X的问题,但这是在Linux(Red Hat)上对我有用的东西。

我的virtualwrapper.sh在

~/.local/bin/virtualenvwrapper.sh

这可能是因为我使用--user标记在本地安装了virtualenvwrapper …

pip install --user virtualenvwrapper

……作为替代冒险的做法使用sudo pip

Although this is an OS X question, here’s what worked for me on Linux (Red Hat).

My virtualwrapper.sh was in

~/.local/bin/virtualenvwrapper.sh

This is probably because I installed virtualenvwrapper locally, using the --user flag…

pip install --user virtualenvwrapper

…as an alternative to the risky practice of using sudo pip.


回答 16

/usr/share/virtualenvwrapper/virtualenvwrapper.sh

我已经在Ubuntu 16.04上安装了它,并找到了这个位置。

/usr/share/virtualenvwrapper/virtualenvwrapper.sh

I’ve installed it on Ubuntu 16.04 and it resulted in this location.


回答 17

/usr/local/bin/virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh

回答 18

小猎犬骨头黑(debian)也有同样的问题。

手动下载软件包并安装对我有用。

I had the same issue in with the beagle bone black(debian).

Manually downloading the package and installing worked for me.


回答 19

对于Ubuntu,
如果您刚刚安装了它,请检查Terminal上的输出,我在发布我的:

Running setup.py install for virtualenv-clone    
Installing virtualenv-clone script to /home/username/.local/bin
Successfully installed virtualenvwrapper virtualenv virtualenv-clone stevedore pbr six
Cleaning up...

第二行告诉您路径。对我来说/home/username/.local/bin

For Ubuntu
If you just installed it, check the output on Terminal, I’m posting mine :

Running setup.py install for virtualenv-clone    
Installing virtualenv-clone script to /home/username/.local/bin
Successfully installed virtualenvwrapper virtualenv virtualenv-clone stevedore pbr six
Cleaning up...

Here the second line tells you the path. For me it was at /home/username/.local/bin


回答 20

点子不会试图让您为难。

问题是基于命令的文件始终安装在/bin文件夹中,它们可以位于系统路径上的任何位置。

我遇到了同样的问题,发现我的文件中有这些文件

~/.local/bin/

文件夹而不是

/usr/loca/bin/

这是常见的情况,但我认为他们将默认路径更改为

~ 或$ HOME

目录,因为它对pip安装更隔离,并提供了apt-get软件包和pip软件包之间的区别。

所以说到这里,您有两种选择,要么转到 .bashrc,然后进行如下更改

# for virtualenv wrapper
export WORKON_HOME=$HOME/Envs
export PROJECT_HOME=$HOME/Devel
source $HOME/.local/bin/virtualenvwrapper.sh

然后在下面创建目录virtualenvwrapper/usr/share/然后像这样符号链接您的virtualwrapper_lazy.sh

sudo ln -s ~/.local/bin/virtualenvwrapper_lazy.sh /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh

并且您可以检查您的workon命令是否正在运行,该命令将列出您现有的virtualenv。

pip will not try to make things difficult for you on purpose.

The thing is commands based files are always installed in /bin folders they can be anywhere on the system path.

I had the same problem and I found that I have these files in my

~/.local/bin/

folder instead of

/usr/loca/bin/

which is the common case, but I think they changed the default path to

~ or $HOME

directory because its more isolate for the pip installations and provides a distinction between apt-get packages and pip packages.

So coming to the point you have two choices here either you go to your .bashrc and make changes like this

# for virtualenv wrapper
export WORKON_HOME=$HOME/Envs
export PROJECT_HOME=$HOME/Devel
source $HOME/.local/bin/virtualenvwrapper.sh

and than create a directory virtualenvwrapper under /usr/share/ and than symlink your virtualwrapper_lazy.sh like this

sudo ln -s ~/.local/bin/virtualenvwrapper_lazy.sh /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh

and you can check if your workon command is working which will list your existing virtualenv’s.


回答 21

如果您pip install virtualenvwrapper不使用sudo来执行,那么普通的用户pip将运行,但由于缺少权限而不会在所需位置复制文件

mortiz@florida:~# sudo pip3 install virtualenvwrapper

使用sudo,文件将在它们各自的路径下创建:

root@florida:/usr/local/bin# ls -ltr
total 8008
-rwxr-xr-x 1 root staff 8136192 Jun 11 17:45 chromedriver
-rwxr-xr-x 1 root staff   41697 Sep  5 16:06 virtualenvwrapper.sh
-rwxr-xr-x 1 root staff    2210 Sep  5 16:06 virtualenvwrapper_lazy.sh
-rwxr-xr-x 1 root staff     215 Sep  5 16:06 pbr
-rwxr-xr-x 1 root staff     218 Sep  5 16:06 virtualenv-clone
-rwxr-xr-x 1 root staff     213 Sep  5 16:06 virtualenv
root@florida:/usr/local/bin# 

在Debian GNU / Linux 9上为我工作

If you execute pip install virtualenvwrapper without sudo as a normal user pip will run but won’t copy the files in the required locations because the lack of permissions.

mortiz@florida:~# sudo pip3 install virtualenvwrapper

Use sudo and the files will be created under their respective paths:

root@florida:/usr/local/bin# ls -ltr
total 8008
-rwxr-xr-x 1 root staff 8136192 Jun 11 17:45 chromedriver
-rwxr-xr-x 1 root staff   41697 Sep  5 16:06 virtualenvwrapper.sh
-rwxr-xr-x 1 root staff    2210 Sep  5 16:06 virtualenvwrapper_lazy.sh
-rwxr-xr-x 1 root staff     215 Sep  5 16:06 pbr
-rwxr-xr-x 1 root staff     218 Sep  5 16:06 virtualenv-clone
-rwxr-xr-x 1 root staff     213 Sep  5 16:06 virtualenv
root@florida:/usr/local/bin# 

Worked for me on Debian GNU/Linux 9


回答 22

就我而言:/home/username/.local/bin/virtualenvwrapper.sh

in my case: /home/username/.local/bin/virtualenvwrapper.sh


回答 23

您是否使用sudo安装了它?在我的情况下是错误。

Have you installed it using sudo? Was the error in my case.