标签归档:easy-install

我可以使用`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']
)

在64位Windows上安装SetupTools

问题:在64位Windows上安装SetupTools

我在Windows 7 64位系统上运行Python 2.7,当我运行setuptools的安装程序时,它告诉我未安装Python 2.7。具体的错误消息是:

`Python Version 2.7 required which was not found in the registry`

我安装的Python版本是:

`Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32`

我正在看setuptools网站,它没有提到64位Windows的任何安装程序。我错过了什么吗,还是必须从源代码安装它?

I’m running Python 2.7 on Windows 7 64-bit, and when I run the installer for setuptools it tells me that Python 2.7 is not installed. The specific error message is:

`Python Version 2.7 required which was not found in the registry`

My installed version of Python is:

`Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32`

I’m looking at the setuptools site and it doesn’t mention any installers for 64-bit Windows. Have I missed something or do I have to install this from source?


回答 0

显然(在OS X上面临相关的64位和32位问题),Windows安装程序中存在一个错误。我偶然发现了这种解决方法,它可能会有所帮助-基本上,您可以创建自己的注册表值,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath然后从中复制InstallPath值HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath。有关更多详细信息,请参见下面的答案。

如果执行此操作,请注意setuptools 只能安装32位库

注意:以下回复提供了更多详细信息,因此也请阅读它们。

Apparently (having faced related 64- and 32-bit issues on OS X) there is a bug in the Windows installer. I stumbled across this workaround, which might help – basically, you create your own registry value HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath and copy over the InstallPath value from HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath. See the answer below for more details.

If you do this, beware that setuptools may only install 32-bit libraries.

NOTE: the responses below offer more detail, so please read them too.


回答 1

问题:您有64位Python和32位安装程序。这将导致扩展模块出现问题。

安装程序找不到Python的原因是Windows 7提供的透明32位仿真。64位和32位程序将写入Windows注册表的不同部分。

64位: HKLM|HKCU\SOFTWARE\

32位:HKLM|HKCU\SOFTWARE\wow6432node\

这意味着64位Python安装程序会写入HKLM\SOFTWARE\Python,而32位setuptools安装程序会查看HKLM\SOFTWARE\wow6432node\Python(这是由Windows自动处理的,程序不会注意到)。这是预期的行为,而不是错误。

通常,您有以下选择:

  • “干净”的方式:如果必须使用32位模块或扩展,请使用32位Python
  • 另一种“干净”的方式:仅在使用64位Python时才使用64位安装程序(请参见下文)
  • 上面的答案表明了什么:复制HKLM\SOFTWARE\PythonHKLM\SOFTWARE\wow6432node\Python,但这导致二进制分发出现问题,因为64位Python无法加载32位编译模块(请勿这样做!)
  • 使用setuptools而不是distutils安装程序(easy_install或pip)安装纯Python模块

例如,对于setuptools本身,您不能将32位安装程序用于64位Python,因为它包含二进制文件。但是在http://www.lfd.uci.edu/~gohlke/pythonlibs/中有一个64位安装程序(其他模块也有许多安装程序)。如今,PyPi上的许多软件包都有二进制发行版,因此您可以通过pip安装它们。

Problem: you have 64-bit Python, and a 32-bit installer. This will cause problems for extension modules.

The reasons why the installer doesn’t finds Python is the transparent 32-bit emulation from Windows 7. 64-bit and 32-bit programs will write to different parts of the Windows registry.

64-bit: HKLM|HKCU\SOFTWARE\

32-bit: HKLM|HKCU\SOFTWARE\wow6432node\.

This means that the 64-bit Python installer writes to HKLM\SOFTWARE\Python, but the 32-bit setuptools installer looks at HKLM\SOFTWARE\wow6432node\Python (this is handled by windows automatically, programs don’t notice). This is expected behavior and not a bug.

Usually, you have these choices:

  • the “clean” way: use 32-bit Python if you have to use 32-bit modules or extensions
  • the other “clean” way: only use 64-bit installers when using 64-bit Python (see below)
  • what the answer above suggests: copy HKLM\SOFTWARE\Python to HKLM\SOFTWARE\wow6432node\Python, but this will cause problems with binary distributions, as 64-bit Python can’t load 32-bit compiled modules (do NOT do this!)
  • install pure Python modules with setuptools instead of the distutils installer (easy_install or pip)

For setuptools itself, for example, you can’t use a 32-bit installer for 64-bit Python as it includes binary files. But there’s a 64-bit installer at http://www.lfd.uci.edu/~gohlke/pythonlibs/ (has many installers for other modules too). Nowadays, many packages on PyPi have binary distributions, so you can install them via pip.


回答 2

我做了一个注册表(.reg)文件,它将自动为您更改注册表。如果安装在“ C:\ Python27”中,它将起作用:

下载32位版本 HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER\SOFTWARE\wow6432node\

下载64位版本 HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER\SOFTWARE\

I made a registry (.reg) file that will automatically change the registry for you. It works if it’s installed in “C:\Python27”:

Download 32-bit version HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER\SOFTWARE\wow6432node\

Download 64-bit version HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER\SOFTWARE\


回答 3

是的,您是对的,问题出在setuptools的64位Python和32位安装程序上。

在Windows上安装64位setuptools的最佳方法是将ez_setup.py下载到C:\ Python27 \ Scripts并运行它。它将下载用于setuptools的适当的64位.egg文件并为您安装。

资料来源:http : //pypi.python.org/pypi/setuptools

PS我建议您不要使用第三方的64位.exe setuptools安装程序或操纵注册表

Yes, you are correct, the issue is with 64-bit Python and 32-bit installer for setuptools.

The best way to get 64-bit setuptools installed on Windows is to download ez_setup.py to C:\Python27\Scripts and run it. It will download appropriate 64-bit .egg file for setuptools and install it for you.

Source: http://pypi.python.org/pypi/setuptools

P.S. I’d recommend against using 3rd party 64-bit .exe setuptools installers or manipulating registry


回答 4

创建一个名为python2.7.reg(注册表文件)的文件,并将其内容放入其中:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help\MainPythonDocumentation]
@="C:\\Python27\\Doc\\python26.chm"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath]
@="C:\\Python27\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath\InstallGroup]
@="Python 2.7"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Modules]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\PythonPath]
@="C:\\Python27\\Lib;C:\\Python27\\DLLs;C:\\Python27\\Lib\\lib-tk"

并确保每条路径都是正确的!

然后运行(合并)并完成:)

Create a file named python2.7.reg (registry file) and put this content into it:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help\MainPythonDocumentation]
@="C:\\Python27\\Doc\\python26.chm"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath]
@="C:\\Python27\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath\InstallGroup]
@="Python 2.7"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Modules]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\PythonPath]
@="C:\\Python27\\Lib;C:\\Python27\\DLLs;C:\\Python27\\Lib\\lib-tk"

And make sure every path is right!

Then run (merge) it and done :)


回答 5

register.py这个要点获取文件。将其保存在您的C驱动器或D驱动器上,转到CMD以运行它:

'python register.py'

然后,您将能够安装它。

Get the file register.py from this gist. Save it on your C drive or D drive, go to CMD to run it with:

'python register.py'

Then you will be able to install it.


回答 6

对于Windows上的64位Python,请下载ez_setup.py并运行它;它将下载适当的.egg文件并为您安装。

由于distutils安装程序兼容性问题,在撰写本文时,.exe安装程序不支持Windows的64位版本的Python 。

For 64-bit Python on Windows download ez_setup.py and run it; it will download the appropriate .egg file and install it for you.

At the time of writing the .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue.


回答 7

要允许Windows安装程序在Windows 7Windows 7中找到已安装的Python目录,请更改要将安装程序安装到的Python安装,然后将已安装的路径添加到InstallPath注册表项的(默认)值中:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Python \ PythonCore \ 2.X \ InstallPath

其中“ X ”是Python版本(即2.5、2.6或2.7)。

To allow Windows installers to find the installed Python directory in Windows 7, OR, change which Python installation to install an installer into, add the installed path into the InstallPath registry key’s (Default) value:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.X\InstallPath

Where “X” is the Python version (that is, 2.5, 2.6, or 2.7).


回答 8

我尝试了上述操作,但将注册表项添加到LOCALMACHINE并没有完成任务。因此,如果您仍然被卡住,请尝试此操作。

Windows注册表编辑器版本5.00

[HKEY_CURRENT_USER \ SOFTWARE \ Python]

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore]

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7]

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7 \ Help]

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7 \ Help \ Main Python文档] @ =“ C:\ Python27 \ Doc \ python272.chm”

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7 \ InstallPath] @ =“ C:\ Python27 \”

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7 \ InstallPath \ InstallGroup] @ =“ Python 2.7”

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7 \ Modules]

[HKEY_CURRENT_USER \ SOFTWARE \ Python \ PythonCore \ 2.7 \ PythonPath] @ =“ C:\ Python27 \ Lib; C:\ Python27 \ DLLs; C:\ Python27 \ Lib \ lib-tk”

将以上内容复制粘贴到记事本中,并将其另存为Python27.reg。现在,按照上述答案中的说明运行/合并文件。(请确保根据您的安装更正了Python安装路径。

上面的答案对本地用户的建议对当前用户来说确实很简单。

I tried the above and adding the registry keys to the LOCALMACHINE was not getting the job done. So in case you are still stuck , try this.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Python]

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore]

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7]

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7\Help]

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7\Help\Main Python Documentation] @=”C:\Python27\Doc\python272.chm”

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7\InstallPath] @=”C:\Python27\”

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7\InstallPath\InstallGroup] @=”Python 2.7″

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7\Modules]

[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.7\PythonPath] @=”C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk”

Copy paste the above in notepad and save it as Python27.reg . Now run/merge the file as mentioned in the answers above. (Make sure the paths of Python installation are corrected as per your installation.

It simply does ,what the above answers suggest for a local machine ,to the current user.


回答 9

这是另一个帖子/主题的链接。我能够运行此脚本来自动注册python 2.7。(确保从.exe要注册的Python 2.x运行它!)

要注册Python 3.x,我必须修改print语法并导入winreg(而不是_winreg),然后运行Python 3 .exe

https://stackoverflow.com/a/29633714/3568893

Here is a link to another post/thread. I was able run this script to automate registration of Python 2.7. (Make sure to run it from the Python 2.x .exe you want to register!)

To register Python 3.x I had to modify the print syntax and import winreg (instead of _winreg), then run the Python 3 .exe.

https://stackoverflow.com/a/29633714/3568893


回答 10

您可以在此处找到许多库的64位安装程序:http : //www.lfd.uci.edu/~gohlke/pythonlibs/

You can find 64bit installers for a lot of libs here: http://www.lfd.uci.edu/~gohlke/pythonlibs/


ImportError:没有名为Crypto.Cipher的模块

问题:ImportError:没有名为Crypto.Cipher的模块

当我尝试运行app.py(Python 3.3,PyCrypto 2.6)时,我的virtualenv不断返回上面列出的错误。我的进口货单是from Crypto.Cipher import AES。我在寻找重复项,您可能会说有重复项,但是我尝试了解决方案(尽管大多数都不是解决方案),但没有任何效果。

您可以在下面查看PyCrypto的文件格式:

When I try to run app.py (Python 3.3, PyCrypto 2.6) my virtualenv keeps returning the error listed above. My import statement is just from Crypto.Cipher import AES. I looked for duplicates and you might say that there are some, but I tried the solutions (although most are not even solutions) and nothing worked.

You can see what the files are like for PyCrypto below:


回答 0

我有同样的问题(尽管在Linux上)。解决方案非常简单-添加:

libraries:
- name: pycrypto
  version: "2.6"

到我的app.yaml文件。由于过去该方法正常工作,因此我认为这是一个新要求。

I had the same problem (though on Linux). The solution was quite simple – add:

libraries:
- name: pycrypto
  version: "2.6"

to my app.yaml file. Since this worked correctly in the past, I assume this is a new requirement.


回答 1

使用进行安装时,在Mac上出现相同的问题pip。然后pycrypto,我使用删除并重新安装了它easy_install,如下所示:

pip uninstall pycrypto
easy_install pycrypto

就像卢克(Luke)所说:如果您在运行这些命令时遇到问题,请确保以admin(sudo)身份运行它们

希望这可以帮助!

编辑:正如winklerr在上面正确指出的那样,pycrypto不再安全。改用pycryptodome,它是一个替代品

I had the same problem on my Mac when installing with pip. I then removed pycrypto and installed it again with easy_install, like this:

pip uninstall pycrypto
easy_install pycrypto

also as Luke commented: If you have trouble running these commands, be sure to run them as admin (sudo)

Hope this helps!

EDIT: As winklerr correctly notes above, pycrypto is no longer safe. Use pycryptodome instead, it is a drop-in replacement


回答 2

我也在Mac上遇到了这个问题,它似乎与通过pip在pycrypto旁边安装了一个不幸的名字相似的“ crypto”模块(不确定该用于什么目的)有关。

该修复程序似乎正在通过pip删除crypto和pycrypto:

sudo pip uninstall crypto
sudo pip uninstall pycrypto

并重新安装pycrypto:

sudo pip install pycrypto

现在,当我执行以下操作时,它可以按预期工作:

from Crypto.Cipher import AES

I ran into this on Mac as well, and it seems to be related to having an unfortunately similarly named “crypto” module (not sure what that is for) installed alongside of pycrypto via pip.

The fix seems to be removing both crypto and pycrypto with pip:

sudo pip uninstall crypto
sudo pip uninstall pycrypto

and reinstalling pycrypto:

sudo pip install pycrypto

Now it works as expected when I do something like:

from Crypto.Cipher import AES

回答 3

在Mac上…如果遇到此问题,请尝试是否可以导入加密货币?

如果是这样..包名是问题CVS c。要解决此问题,只需将这些行添加到脚本的顶部。

import crypto
import sys
sys.modules['Crypto'] = crypto

您知道应该能够成功导入paramiko。

On the mac… if you run into this.. try to see if you can import crypto instead?

If so.. the package name is the issue C vs c. To get around this.. just add these lines to the top of your script.

import crypto
import sys
sys.modules['Crypto'] = crypto

You know should be able to import paramiko successfully.


回答 4

正在卸载cryptopycrypto在我身上工作。然后仅安装pycrypto

pip uninstall crypto 
pip uninstall pycrypto 
pip install pycrypto

Uninstalling crypto and pycrypto works on me. Then install only pycrypto:

pip uninstall crypto 
pip uninstall pycrypto 
pip install pycrypto

回答 5

我找到了解决方案。问题可能是区分大小写(在Windows上)。

只需更改文件夹的名称:

  • C:\Python27\Lib\site-packages\crypto
  • 至: C:\Python27\Lib\site-packages\Crypto

这是在安装pycrypto之后命名文件夹的方式:

我将其更改为:

现在,以下代码可以正常工作:

I found the solution. Issue is probably in case sensitivity (on Windows).

Just change the name of the folder:

  • C:\Python27\Lib\site-packages\crypto
  • to: C:\Python27\Lib\site-packages\Crypto

This is how folder was named after installation of pycrypto:

I’ve changed it to:

And now the following code works fine:


回答 6

警告:请勿使用 pycrypto

正如你可以在阅读此页,的用法pycrypto不是安全了:

Pycrypto容易受block_templace.c中ALGnew函数中基于堆的缓冲区溢出的影响。它允许远程攻击者在python应用程序中执行任意代码。它被分配了CVE-2013-7459号。

自2014年6月20日以来,Pycrypto尚未发布对该漏洞的任何修复程序,也没有对该项目进行任何提交。

解决方案:使用Python3和pycryptodome

TL; DR: pip3 install pycryptodome

确保先卸载其他版本cryptopycrypto

设置新的虚拟环境

要安装虚拟环境并设置所有内容,请使用以下命令:

# install python3 and pip3
sudo apt update
sudo apt upgrade
sudo apt install python3
sudo apt install python3-pip

# install virtualenv
pip3 install virtualenv

# install and create a virtual environment in your target folder
mkdir target_folder
cd target_folder
python3 -m virtualenv .

# now activate your venv and install pycryptodome
source bin/activate
pip3 install pycryptodome

# check if everything worked: 
# start the interactive python console and import the Crypto module
# when there is no import error then it worked
python
>>> from Crypto.Cipher import AES
>>> exit()

# don't forget to deactivate your venv again
deactivate

有关更多信息,请参见pycryptodome.org。

WARNING: Don’t use pycrypto anymore!

As you can read on this page, the usage of pycrypto is not safe anymore:

Pycrypto is vulnerable to a heap-based buffer overflow in the ALGnew function in block_templace.c. It allows remote attackers to execute arbitrary code in the python application. It was assigned the CVE-2013-7459 number.

Pycrypto didn’t release any fix to that vulnerability and no commit was made to the project since Jun 20, 2014.

Use Python3 and pycryptodome instead!

pip3 uninstall crypto 
pip3 uninstall pycrypto 
pip3 install pycryptodome

Make sure to uninstall other versions of crypto or pycrypto first because both packages install under the same folder Crypto where also pycryptodome will be installed.

Best practice: virtual environments

In order to avoid problems with pip packages in different versions or packages that install under the same folder (i.e. pycrypto and pycryptodome) you can make use of a so called virtual environment. There, the installed pip packages can be managed for every single project individually.

To install a virtual environment and setup everything, use the following commands:

# install python3 and pip3
sudo apt update
sudo apt upgrade
sudo apt install python3
sudo apt install python3-pip

# install virtualenv
pip3 install virtualenv

# install and create a virtual environment in your target folder
mkdir target_folder
cd target_folder
python3 -m virtualenv .

# now activate your venv and install pycryptodome
source bin/activate
pip3 install pycryptodome

# check if everything worked: 
# start the interactive python console and import the Crypto module
# when there is no import error then it worked
python
>>> from Crypto.Cipher import AES
>>> exit()

# don't forget to deactivate your venv again
deactivate

For more information, see pycryptodome.org


回答 7

输入命令:

sudo pip install pycrypto

type command:

sudo pip install pycrypto

回答 8

如果您使用的是redhat,fedora,centos:

sudo yum install pycrypto

就我而言,我不会使用pip安装它

if you are using redhat,fedora, centos :

sudo yum install pycrypto

for my case I coouldnot install it using pip


回答 9

我遇到了同样的问题 'ImportError: No module named Crypto.Cipher',因为在OSX 10.8.5(Mountain Lion)上将GoogleAppEngineLauncher(版本> 1.8.X)与GAE Boilerplate一起使用。在具有python 2.7运行时的Google App Engine SDK中,建议使用pyCrypto 2.6。对我有用的解决方案是…

1)下载pycrypto2.6源将其解压缩到某处(~/Downloads/pycrypto26

例如,git clone https://github.com/dlitz/pycrypto.git

2)cdcd ~/Downloads/pycrypto26)然后

3)在上一个文件夹中执行以下终端命令,以便在GAE文件夹中手动安装pyCrypto 2.6。

sudo python setup.py install --install-lib /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine

I’ve had the same problem 'ImportError: No module named Crypto.Cipher', since using GoogleAppEngineLauncher (version > 1.8.X) with GAE Boilerplate on OSX 10.8.5 (Mountain Lion). In Google App Engine SDK with python 2.7 runtime, pyCrypto 2.6 is the suggested version. The solution that worked for me was…

1) Download pycrypto2.6 source extract it somewhere(~/Downloads/pycrypto26)

e.g., git clone https://github.com/dlitz/pycrypto.git

2) cd (cd ~/Downloads/pycrypto26) then

3) Execute the following terminal command inside the previous folder in order to install pyCrypto 2.6 manually in GAE folder.

sudo python setup.py install --install-lib /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine

回答 10

如果您是macOS,请将lib文件夹重命名lib/python3.7/site-packages/cryptolib/python3.7/site-packages/Crypto

If you an macos, rename lib folder lib/python3.7/site-packages/crypto to lib/python3.7/site-packages/Crypto


回答 11

尝试使用pip3

sudo pip3 install pycrypto

Try with pip3:

sudo pip3 install pycrypto

回答 12

加载通过pip安装的python模块可能是一个问题。参考此答案无法从site-packages目录加载通过pip安装的Python模块,并尝试类似

python -m pip install pycrypto

It could be a problem of loading python modules installed via pip. Refer to this answer Can’t load Python modules installed via pip from site-packages directory and try something like

python -m pip install pycrypto

回答 13

为我工作(Ubuntu 17.10)

删除venv并使用python v3.6重新创建

pip3 install PyJWT
sudo apt-get install build-essential libgmp3-dev python3-dev
pip3 install cryptography
pip3 install pycryptodome
pip3 install pycryptodomex

Pycrypto已过时,有问题,使用Pycryptodome

Worked for me (Ubuntu 17.10)

Removing venv and creating it again with python v3.6

pip3 install PyJWT
sudo apt-get install build-essential libgmp3-dev python3-dev
pip3 install cryptography
pip3 install pycryptodome
pip3 install pycryptodomex

Pycrypto is deprecated, had problems with it, used Pycryptodome


回答 14

我通过将首字母大写更改为大写来解决此问题。确保“从Crypto.Cipher导入AES”而不是“从crypto.Cipher导入AES”。

I solve this problem by change the first letter case to upper. Make sure ”from Crypto.Cipher import AES” not ”from crypto.Cipher import AES”.


回答 15

对于CentOS 7.4,我首先安装了pip,然后使用pip安装了pycrypto:

> sudo yum -y install python-pip 
> sudo python -m pip install pycrypto

For CentOS 7.4 I first installed pip and then pycrypto using pip:

> sudo yum -y install python-pip 
> sudo python -m pip install pycrypto

回答 16

迄今为止,from Crypto.Cipher import AES即使我安装/重新安装了pycrypto几次,导入时也遇到相同的问题。最终是因为pip默认为python3。

~ pip --version
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

使用pip2安装pycrypto应该可以解决此问题。

To date, I’m having same issue when importing from Crypto.Cipher import AES even when I’ve installed/reinstalled pycrypto a few times. End up it’s because pip defaulted to python3.

~ pip --version
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

installing pycrypto with pip2 should solve this issue.


回答 17

对于Windows 7:

我遇到了这个错误“模块错误Crypo.Cipher导入AES”

要在Windows中安装Pycrypto,

在命令提示符中尝试此操作,

设置路径= C:\ Python27 \ Scripts(即easy_install所在的路径)

然后执行以下命令

easy_install pycrypto

对于Ubuntu:

试试这个,

从“ https://pypi.python.org/pypi/pycrypto下载Pycrypto

然后使用终端将当前路径更改为下载路径:

例如:root @ xyz-virtual-machine:〜/ pycrypto-2.6.1#

然后使用终端执行以下命令:

python setup.py安装

对我有用。希望为所有人服务。

For Windows 7:

I got through this error “Module error Crypo.Cipher import AES”

To install Pycrypto in Windows,

Try this in Command Prompt,

Set path=C:\Python27\Scripts (i.e path where easy_install is located)

Then execute the following,

easy_install pycrypto

For Ubuntu:

Try this,

Download Pycrypto from “https://pypi.python.org/pypi/pycrypto

Then change your current path to downloaded path using your terminal:

Eg: root@xyz-virtual-machine:~/pycrypto-2.6.1#

Then execute the following using the terminal:

python setup.py install

It’s worked for me. Hope works for all..


回答 18

可以通过安装C ++编译器(python27或python26)来解决此问题。从Microsoft https://www.microsoft.com/zh-cn/download/details.aspx?id=44266下载它,然后重新运行命令:pip install pycrypto当您杀死.NET 进程时运行gui Web访问easy_install.exe

This problem can be fixed by installing the C++ compiler (python27 or python26). Download it from Microsoft https://www.microsoft.com/en-us/download/details.aspx?id=44266 and re-run the command : pip install pycrypto to run the gui web access when you kill the process of easy_install.exe.


回答 19

也许您应该这样做:pycryptodome == 3.6.1将其添加到requirements.txt并安装,这应该消除错误报告。这个对我有用!

Maybe you should this: pycryptodome==3.6.1 add it to requirements.txt and install, which should eliminate the error report. it works for me!


回答 20

这对我有用

pip install pycryptodome==3.4.3

This worked for me

pip install pycryptodome==3.4.3

回答 21

嗯,这可能会出现奇怪,但安装后pycrypto还是pycryptodome,我们需要更新的目录名cryptoCryptolib/site-packages

参考

Well this might appear weird but after installing pycrypto or pycryptodome , we need to update the directory name crypto to Crypto in lib/site-packages

Reference


回答 22

我是3.7。在我尝试安装加密货币后,问题仍然存在。在我的情况下,pycrypto只是失败了。所以最后我的构建通过下面的包传递:pip install pycryptodome

I’m with 3.7. The issue remains after I try to install crypto. And pycrypto just fails in my case. So in the end my build passed via package below: pip install pycryptodome


如何在Windows上点子或easy_install tkinter

问题:如何在Windows上点子或easy_install tkinter

我的空闲状态抛出错误,并指出tkinter无法导入。

有没有一种简单的方法可以tkinter通过pip或安装easy_install

似乎有很多软件包名称在出现……

此版本以及其他各种各样的版本tkinter-pypy均无效。

pip install python-tk

我在Windows上使用python 2.7,不能apt-get

谢谢。

My Idle is throwing errors that and says tkinter can’t be imported.

Is there a simple way to install tkinter via pip or easy_install?

There seem to be a lot of package names flying around for this…

This and other assorted variations with tkinter-pypy aren’t working.

pip install python-tk

I’m on Windows with Python 2.7 and I don’t have apt-get or other system package managers.


回答 0

好吧,我可以在这里看到两个解决方案:

1)按照适用于PythonDocs-Tkinter安装适用于Windows):

所有标准的Python发行版都包含Tkinter(以及从Python 3.1开始的ttk)。使用支持Tk 8.5或更高版本以及ttk的Python版本很重要。我们建议从ActiveState安装“ ActivePython”发行版,其中包括您需要的所有内容。

在您的Web浏览器中,转到Activestate.com,然后按照链接下载Windows版ActivePython社区版。确保您下载的是3.1或更高版本,而不是2.x版本。

运行安装程序,然后继续。最后,您将获得一个全新的ActivePython安装,例如位于C:\python32。在Windows命令提示符或“开始”菜单的“运行…”命令中,您应该能够通过以下方式运行Python Shell:

% C:\python32\python

这应该给您Python命令提示符。在提示符下,输入以下两个命令:

>>> import tkinter
>>> tkinter._test()

这应该会弹出一个小窗口。窗口顶部的第一行应显示“这是Tcl / Tk版本8.5”;确保它不是8.4!

2)卸载64位Python,然后安装32位Python。

Well I can see two solutions here:

1) Follow the Docs-Tkinter install for Python (for Windows):

Tkinter (and, since Python 3.1, ttk) are included with all standard Python distributions. It is important that you use a version of Python supporting Tk 8.5 or greater, and ttk. We recommend installing the “ActivePython” distribution from ActiveState, which includes everything you’ll need.

In your web browser, go to Activestate.com, and follow along the links to download the Community Edition of ActivePython for Windows. Make sure you’re downloading a 3.1 or newer version, not a 2.x version.

Run the installer, and follow along. You’ll end up with a fresh install of ActivePython, located in, e.g. C:\python32. From a Windows command prompt, or the Start Menu’s “Run…” command, you should then be able to run a Python shell via:

% C:\python32\python

This should give you the Python command prompt. From the prompt, enter these two commands:

>>> import tkinter
>>> tkinter._test()

This should pop up a small window; the first line at the top of the window should say “This is Tcl/Tk version 8.5”; make sure it is not 8.4!

2) Uninstall 64-bit Python and install 32 bit Python.


回答 1

Tkinter库在每个Python安装中都是内置的。而且由于您使用的是Windows,我相信您是通过Python的网站上的二进制文件安装的吗?

如果是这样,那么很可能您输入的命令是错误的。它应该是:

import Tkinter as tk

注意Tkinter开头的大写字母T。

对于Python 3,

import tkinter as tk

The Tkinter library is built-in with every Python installation. And since you are on Windows, I believe you installed Python through the binaries on their website?

If so, Then most probably you are typing the command wrong. It should be:

import Tkinter as tk

Note the capital T at the beginning of Tkinter.

For Python 3,

import tkinter as tk

回答 2

如果您使用virtualenv,则可以使用sudo apt-get install python-tk(python2),sudo apt-get install python3-tk(python3)安装tkinter,并且在虚拟环境中也可以正常工作

If you are using virtualenv, it is fine to install tkinter using sudo apt-get install python-tk(python2), sudo apt-get install python3-tk(python3), and and it will work fine in the virtual environment


回答 3

在安装时,请确保Tcl/Tk选择下Will be installed on hard drive。如果安装时带有左侧的叉号,则不会安装Tkinter。

Python 3也是如此:

When installing make sure that under Tcl/Tk you select Will be installed on hard drive. If it is installing with a cross at the left then Tkinter will not be installed.

The same goes for Python 3:


回答 4

当您为Windows安装python时,请使用标准选项或安装它要求的所有内容。我收到错误消息是因为我取消选择了tcl。

When you install python for Windows, use the standard option or install everything it asks. I got the error because I deselected tcl.


回答 5

在Linux中也有同样的问题。这解决了。(我正在使用Debian 9衍生的本生氦气)

$ sudo apt-get install python3-tk

Had the same problem in Linux. This solved it. (I’m on Debian 9 derived Bunsen Helium)

$ sudo apt-get install python3-tk


回答 6

我发布的是最佳答案,重新引用了我认为没有用的文档。

如果您在安装窗口中选择了tkinter,则会在Windows IFF上将python install打包在一起。

解决方法是修复安装(通过卸载GUI即可),然后选择安装tk。在此过程中,您可能需要指向或重新下载二进制文件。直接从activestate下载对我不起作用。

这是人们在Windows上经常遇到的问题,因为如果您不知道TCL / TK是什么,很容易不想安装它,但是Matplotlib等需要它。

I’m posting as the top answer requotes the documentation which I didn’t find useful.

tkinter comes packaged with python install on windows IFF you select it during the install window.

The solution is to repair the installation (via uninstall GUI is fine), and select to install tk this time. You may need to point at or redownload the binary in this process. Downloading directly from activestate did not work for me.

This is a common problem people have on windows as it’s easy to not want to install TCL/TK if you don’t know what it is, but Matplotlib etc require it.


回答 7

在python中,Tkinter是默认软件包,您可以修复安装并选择Tcl / Tk。运行此命令时,应按以下方式安装DDL:

In python, Tkinter was a default package, you can repair the installation and select Tcl/Tk. When you run this, DDL should be installed like so:


回答 8

我在Win-8和python-3.4 32位上也遇到了类似的问题,可以通过从python.org下载相同版本来解决。

下一步将是点击修复按钮并安装Tk / tkinter软件包,或者只是修复。现在应该获得Python34 / Lib / tkinter模块。导入tkinter应该工作..

I had the similar problem with Win-8 and python-3.4 32 bit , I got it resolved by downloading same version from python.org .

Next step will be to hit the repair button and Install the Tk/tkinter Package or Just hit the repair. Now should get Python34/Lib/tkinter Module present. The import tkinter should work ..


回答 9

在内部cmd,运行命令pip install tk和Tkinter应该安装。

Inside cmd, run command pip install tk and Tkinter should install.


回答 10

最简单的方法:

cd C:\Users\%User%\AppData\Local\Programs\Python\Python37\Scripts> 
pip install pythonds 

Easiest way to do this:

cd C:\Users\%User%\AppData\Local\Programs\Python\Python37\Scripts> 
pip install pythonds 


回答 11

如果您使用的是python 3.4.1,则只需编写此行,from tkinter import *这会将模块中的所有内容放入程序的默认命名空间。实际上,不是像tkinter.Button您说的那样说一个按钮Button

if your using python 3.4.1 just write this line from tkinter import * this will put everything in the module into the default namespace of your program. in fact instead of referring to say a button like tkinter.Button you just type Button


安装几乎所有库的pip问题

问题:安装几乎所有库的pip问题

我很难用pip安装几乎所有东西。我是编码的新手,所以我认为这可能是我做错了的事情,因此选择easy_install来完成我需要完成的大部分工作,而这种工作通常是有效的。但是,现在我正在尝试下载nltk库,但都没有完成任务。

我尝试进入

sudo pip install nltk

但得到以下回应:

/Library/Frameworks/Python.framework/Versions/2.7/bin/pip run on Sat May  4 00:15:38 2013
Downloading/unpacking nltk

  Getting page https://pypi.python.org/simple/nltk/
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link]/simple/nltk/ when looking for download links for nltk

  Getting page [need more reputation to post link]/simple/
  Could not fetch URL https://pypi.python. org/simple/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Cannot fetch index base URL [need more reputation to post link]

  URLs to search for versions for nltk:
  * [need more reputation to post link]
  Getting page [need more reputation to post link]
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Could not find any downloads that satisfy the requirement nltk

No distributions at all found for nltk

Exception information:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1026, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/index.py", line 171, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for nltk

--easy_install installed fragments of the library and the code ran into trouble very quickly upon trying to run it.

对这个问题有什么想法吗?在此期间,我非常感谢您提供一些反馈意见,以帮助我解决问题或解决问题。

I have a difficult time using pip to install almost anything. I’m new to coding, so I thought maybe this is something I’ve been doing wrong and have opted out to easy_install to get most of what I needed done, which has generally worked. However, now I’m trying to download the nltk library, and neither is getting the job done.

I tried entering

sudo pip install nltk

but got the following response:

/Library/Frameworks/Python.framework/Versions/2.7/bin/pip run on Sat May  4 00:15:38 2013
Downloading/unpacking nltk

  Getting page https://pypi.python.org/simple/nltk/
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link]/simple/nltk/ when looking for download links for nltk

  Getting page [need more reputation to post link]/simple/
  Could not fetch URL https://pypi.python. org/simple/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Cannot fetch index base URL [need more reputation to post link]

  URLs to search for versions for nltk:
  * [need more reputation to post link]
  Getting page [need more reputation to post link]
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Could not find any downloads that satisfy the requirement nltk

No distributions at all found for nltk

Exception information:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1026, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/index.py", line 171, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for nltk

--easy_install installed fragments of the library and the code ran into trouble very quickly upon trying to run it.

Any thoughts on this issue? I’d really appreciate some feedback on how I can either get pip working or something to get around the issue in the meantime.


回答 0

我发现将pypi主机指定为受信任就足够了。例:

pip install --trusted-host pypi.python.org pytest-xdist
pip install --trusted-host pypi.python.org --upgrade pip

这解决了以下错误:

  Could not fetch URL https://pypi.python.org/simple/pytest-cov/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) - skipping
  Could not find a version that satisfies the requirement pytest-cov (from versions: )
No matching distribution found for pytest-cov

2018年4月更新:对于任何收到TLSV1_ALERT_PROTOCOL_VERSION错误的人:与OP的受信任主机/验证问题或此答案无关。而是TLSV1错误是因为您的解释器不支持TLS v1.2,所以您必须升级您的解释器。例如见https://news.ycombinator.com/item?id=13539034http://pyfound.blogspot.ca/2017/01/time-to-upgrade-your-python-tls-v12.htmlHTTPS ://bugs.python.org/issue17128

2019年2月更新:对于某些更新点子可能就足够了。如果以上错误阻止您执行此操作,请使用get-pip.py。例如在Linux上,

curl https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

有关更多详细信息,参见https://pip.pypa.io/en/stable/installing/

I found it sufficient to specify the pypi host as trusted. Example:

pip install --trusted-host pypi.python.org pytest-xdist
pip install --trusted-host pypi.python.org --upgrade pip

This solved the following error:

  Could not fetch URL https://pypi.python.org/simple/pytest-cov/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) - skipping
  Could not find a version that satisfies the requirement pytest-cov (from versions: )
No matching distribution found for pytest-cov

Update April 2018: To anyone getting the TLSV1_ALERT_PROTOCOL_VERSION error: it has nothing to do with trusted-host/verification issue of the OP or this answer. Rather the TLSV1 error is because your interpreter does not support TLS v1.2, you must upgrade your interpreter. See for example https://news.ycombinator.com/item?id=13539034, http://pyfound.blogspot.ca/2017/01/time-to-upgrade-your-python-tls-v12.html and https://bugs.python.org/issue17128.

Update Feb 2019: For some it may be sufficient to upgrade pip. If the above error prevents you from doing this, use get-pip.py. E.g. on Linux,

curl https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

More details at https://pip.pypa.io/en/stable/installing/.


回答 1

我使用的是pip版本,9.0.1并且存在相同的问题,以上所有答案都无法解决问题,并且由于其他原因,我无法通过brew安装python / pip。

升级点子即可9.0.3解决问题。而且因为我无法使用pip升级pip,所以我下载了源代码并手动进行了安装。

  1. -从下载PIP的正确版本https://pypi.org/simple/pip/
  2. sudo python3 pip-9.0.3.tar.gz -安装点子

或者您可以使用以下方法安装更新的点子:

curl https://bootstrap.pypa.io/get-pip.py | python

I used pip version 9.0.1 and had the same issue, all the answers above didn’t solve the problem, and I couldn’t install python / pip with brew for other reasons.

Upgrading pip to 9.0.3 solved the problem. And because I couldn’t upgrade pip with pip I downloaded the source and installed it manually.

  1. Download the correct version of pip from – https://pypi.org/simple/pip/
  2. sudo python3 pip-9.0.3.tar.gz – Install pip

Or you can install newer pip with:

curl https://bootstrap.pypa.io/get-pip.py | python

回答 2

Pypi删除了对小于1.2的TLS版本的支持

您需要重新安装Pip,然后执行

curl https://bootstrap.pypa.io/get-pip.py | python

或对于全局Python:

curl https://bootstrap.pypa.io/get-pip.py | sudo python

Pypi removed support for TLS versions less than 1.2

You need to re-install Pip, do

curl https://bootstrap.pypa.io/get-pip.py | python

or for global Python:

curl https://bootstrap.pypa.io/get-pip.py | sudo python

回答 3

我使用的是pip3版本9.0.1,最近无法通过命令安装任何软件包pip3 install

Mac OS版本:EI Captain 10.11.5

python版本: 3.5

我尝试了命令:

curl https://bootstrap.pypa.io/get-pip.py | python

它对我不起作用。

因此,我10.0.0通过输入以下命令卸载了较旧的pip并安装了最新版本:

python3 -m pip uninstall pip setuptools
curl https://bootstrap.pypa.io/get-pip.py | python3

现在我的问题解决了。如果您使用的是python2,则可以将python3替换为python。我希望它也对您有用。

顺便说一下,对于像我这样的新秀,您必须输入代码: sudo -i

获得根本权利:)祝你好运!

I used pip3 version 9.0.1 and was unable to install any packages recently via the commandpip3 install.

Mac os version: EI Captain 10.11.5.

python version: 3.5

I tried the command:

curl https://bootstrap.pypa.io/get-pip.py | python

It didn’t work for me.

So I uninstalled the older pip and installed the newest version10.0.0 by entering this:

python3 -m pip uninstall pip setuptools
curl https://bootstrap.pypa.io/get-pip.py | python3

Now my problem was solved. If you are using the python2, you can substitute the python3 with python. I hope it also works for you.

By the way, for some rookies like me, you have to enter the code: sudo -i

to gain the root right :) Good luck!


回答 4

您可能会看到此错误;也可以在这里看到。

最简单的解决方法是将pip降级为不使用SSL:的点easy_install pip==1.2.1。这会使您失去使用SSL的安全优势。真正的解决方案是使用链接到最新SSL库的Python发行版。

You’re probably seeing this bug; see also here.

The easiest workaround is to downgrade pip to one that doesn’t use SSL: easy_install pip==1.2.1. This loses you the security benefit of using SSL. The real solution is to use a Python distribution linked to a more recent SSL library.


回答 5

SSL错误的另一个原因可能是糟糕的系统时间–如果证书与当前时间相距太远,证书将无法验证。

Another cause of SSL errors can be a bad system time – certificates won’t validate if it’s too far off from the present.


回答 6

对我有用的唯一解决方案是:

sudo curl https://bootstrap.pypa.io/get-pip.py | 须藤python

The only solution that worked for me is:

sudo curl https://bootstrap.pypa.io/get-pip.py | sudo python


回答 7

我通过添加--trusted-host pypi.python.org选项解决了类似的问题

I solved a similar problem by adding the --trusted-host pypi.python.org option


回答 8

要安装任何其他软件包,我必须使用最新版本的pip,因为9.0.1存在此SSL问题。要通过点子本身升级点子,我必须首先解决此SSL问题。要跳出这个无尽的循环,我发现这是唯一对我有用的方法。

  1. 在此页面中找到最新版本的pip:https//pypi.org/simple/pip/
  2. 下载.whl最新版本的文件。
  3. 使用pip安装最新的pip。(在这里使用您自己的最新版本)

须藤点安装pip-10.0.1-py2.py3-none-any.whl

现在pip是最新版本,可以安装任何东西。

To install any other package I have to use the latest version of pip, since the 9.0.1 has this SSL problem. To upgrade the pip by pip itself, I have to solve this SSL problem first. To jump out of this endless loop, I find this only way that works for me.

  1. Find the latest version of pip in this page: https://pypi.org/simple/pip/
  2. Download the .whl file of the latest version.
  3. Use pip to install the latest pip. (Use your own latest version here)

sudo pip install pip-10.0.1-py2.py3-none-any.whl

Now the pip is the latest version and can install anything.


回答 9

解决方案 -通过标记以下受信任的主机来安装任何软件包

  • pypi.python.org
  • pypi.org
  • files.pythonhosted.org

临时解决方案

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}

永久解决方案 -将您的PIP(9.0.1版本的问题)更新为最新版本。

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org pytest-xdist

python -m pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade pip

Solution – Install any package by marking below hosts trusted

  • pypi.python.org
  • pypi.org
  • files.pythonhosted.org

Temporary solution

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}

Permanent solution – Update your PIP(problem with version 9.0.1) to latest.

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org pytest-xdist

python -m pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade pip

回答 10

macOS Sierra 10.12.6。无法通过pip安装任何东西(通过homebrew安装的python)。以上所有答案均无效。

最终,从python 3.5升级到3.6可行。

brew update
brew doctor #(in case you see such suggestion by brew)

然后按照brew的任何其他建议,即覆盖python的链接。

macOS Sierra 10.12.6. Wasn’t able to install anything through pip (python installed through homebrew). All the answers above didn’t work.

Eventually, upgrade from python 3.5 to 3.6 worked.

brew update
brew doctor #(in case you see such suggestion by brew)

then follow any additional suggestions by brew, i.e. overwrite link to python.


回答 11

我有同样的问题。我刚刚将python从2.7.0更新为2.7.15。它解决了这个问题。

您可以在此处下载。

I had the same problem. I just updated the python from 2.7.0 to 2.7.15. It solves the problem.

You can download here.


回答 12

正如blackjar在上面发布的,以下几行对我有用

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx

您需要同时给出全部三个--trusted-host options。看完答案后,我只尝试了第一个,但那样对我来说并不起作用。

As posted above by blackjar, the below lines worked for me

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx

You need to give all three --trusted-host options. I was trying with only the first one after looking at the answers but it didn’t work for me like that.


回答 13

您还可以使用conda安装软件包:请参见http://conda.pydata.org

conda install nltk

使用conda的最佳方法是下载Miniconda,但您也可以尝试

pip install conda
conda init
conda install nltk

You can also use conda to install packages: See http://conda.pydata.org

conda install nltk

The best way to use conda is to download Miniconda, but you can also try

pip install conda
conda init
conda install nltk

回答 14

对我来说,最新的pip(1.5.6)可以与不安全的nltk软件包一起使用,如果您只是告诉它不要对安全性如此挑剔的话:

pip install --upgrade --force-reinstall --allow-all-external --allow-unverified ntlk nltk

For me, the latest pip (1.5.6) works fine with the insecure nltk package if you just tell it not to be so picky about security:

pip install --upgrade --force-reinstall --allow-all-external --allow-unverified ntlk nltk

回答 15

试过了

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx 

最终得出结论,不太了解为什么更改了pypi.python.org域。

tried

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx 

and finally worked out, not quite understand why the domain pypi.python.org is changed.


回答 16

如果通过代理连接,请执行export https_proxy=<your_proxy>(在Unix或Git Bash上),然后重试安装。

如果您使用的是Windows cmd,则更改为set https_proxy=<your_proxy>

If you’re connecting through a proxy, execute export https_proxy=<your_proxy> (on Unix or Git Bash) and then retry installation.

If you’re using Windows cmd, this changes to set https_proxy=<your_proxy>.


回答 17

为了解决此问题,我在Windows 7上执行了以下操作。

c:\ Program Files \ Python36 \ Scripts> pip install beautifulsoup4 –trusted-host *

–trusted-host似乎可以解决SSL问题,*表示每个主机。

当然这是行不通的,因为您会遇到其他错误,因为没有版本可以满足beautifulsoup4的要求,但是我认为该问题与一般性问题无关。

I did the following on Windows 7 to solve this problem.

c:\Program Files\Python36\Scripts> pip install beautifulsoup4 –trusted-host *

The –trusted-host seems to fix the SSL issue and * means every host.

Of course this does not work because you get other errors since there is no version that satisfies the requirement beautifulsoup4, but I don’t think that issue is related to the general question.


回答 18

只需卸载并重新安装将为您锻炼的pip软件包即可。

Mac OS版本:高Sierra 10.13.6

python版本:3.7

因此,我通过输入以下命令卸载了较旧的pip并安装了最新的版本10.0.0:

python3 -m pip uninstall pip setuptools

curl https://bootstrap.pypa.io/get-pip.py | python3

现在我的问题解决了。如果您使用的是python2,则可以将python3替换为python。我希望它也对您有用。

Just uninstall and reinstall pip packages it will workout for you guys.

Mac os version: high Sierra 10.13.6

python version: 3.7

So I uninstalled the older pip and installed the newest version10.0.0 by entering this:

python3 -m pip uninstall pip setuptools

curl https://bootstrap.pypa.io/get-pip.py | python3

Now my problem was solved. If you are using the python2, you can substitute the python3 with python. I hope it also works for you.


回答 19

如果只是关于nltk,我曾经遇到过类似的问题。尝试按照以下安装指南进行操作。 安装NLTK

如果确定它不能与任何其他模块一起使用,则可能是您安装了不同版本的Python时遇到了问题。

或尝试一下,看是否已安装pip 。:

sudo apt-get install python-pip python-dev build-essential 

看看是否可行。

If it is only about nltk, I once faced similar problem. Try following guide for installation. Install NLTK

If you are sure it doesn’t work with any other module, you may have problem with different versions of Python installed.

Or Give It a Try to see if it says pip is already installed.:

sudo apt-get install python-pip python-dev build-essential 

and see if it works.


回答 20

我通过以下步骤解决了此问题(在les 11sp2上)

zypper remove pip
easy_install pip=1.2.1
pip install --upgrade scons

这是puppet中的相同步骤(适用于所有发行版)

  package { 'python-pip':
    ensure => absent,
  }
  exec { 'python-pip':
    command  => '/usr/bin/easy_install pip==1.2.1',
    require  => Package['python-pip'],
  }
  package { 'scons': 
    ensure   => latest,
    provider => pip,
    require  => Exec['python-pip'],
  }

I solved this issue with the following steps (on sles 11sp2)

zypper remove pip
easy_install pip=1.2.1
pip install --upgrade scons

Here are the same steps in puppet (which should work on all distros)

  package { 'python-pip':
    ensure => absent,
  }
  exec { 'python-pip':
    command  => '/usr/bin/easy_install pip==1.2.1',
    require  => Package['python-pip'],
  }
  package { 'scons': 
    ensure   => latest,
    provider => pip,
    require  => Exec['python-pip'],
  }

回答 21

在Mac Python 2.7.15rc1上使用python的最新版本 https://bugs.python.org/issue17128

Use Latest version of python on mac Python 2.7.15rc1 https://bugs.python.org/issue17128


回答 22

我在PyCharm中遇到了这个问题,将点子升级到10.0.1时,出现了“在模块中找不到’main’的错误”点子。

我可以通过安装pip 9.0.3来解决此问题,如在其他一些线程中所见。这些是我执行的步骤:

  1. https://pypi.org/simple/pip/下载了9.0.3版本的pip (因为无法使用pip进行安装)。
  2. 从tar.gz安装pip 9.0.3 python -m pip安装pip-9.0.3.tar.gz

此后,一切开始起作用。

I had this with PyCharm and upgrading pip to 10.0.1 broke pip with “‘main’ not found in module” error.

I could solve this problem by installing pip 9.0.3 as seen in some other thread. These are the steps I did:

  1. Downloaded 9.0.3 version of pip from https://pypi.org/simple/pip/ (since pip couldn’t be used to install it).
  2. Install pip 9.0.3 from tar.gz python -m pip install pip-9.0.3.tar.gz

Everything started to work after that.


回答 23

该视频教程对我有用:

$ curl https://bootstrap.pypa.io/get-pip.py | python

This video tutorial worked for me:

$ curl https://bootstrap.pypa.io/get-pip.py | python

回答 24

我通过在Mac上更新Python3 Virtualenv解决了此问题。我引用了网站https://gist.github.com/pandafulmanda/730a9355e088a9970b18275cb9eadef3
brew install python3
pip3 install virtualenv

I solved this issue by update Python3 Virtualenv on my mac. I reference the site https://gist.github.com/pandafulmanda/730a9355e088a9970b18275cb9eadef3
brew install python3
pip3 install virtualenv


回答 25

我尝试了一些流行的答案,但是仍然无法使用安装任何库/软件包pip install

我的特定错误是'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain使用Windows Miniconda(安装程序Miniconda3-py37_4.8.3-Windows-x86.exe)。

当我这样做时,它终于可以工作了: pip install -r requirements.txt --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

具体来说,我添加了它以使其工作: --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

I tried some of the popular answers, but still could not install any libraries/packages using pip install.

My specific error was 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain using Miniconda for Windows (installer Miniconda3-py37_4.8.3-Windows-x86.exe).

It finally works when I did this: pip install -r requirements.txt --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

Specifically, I added this to make it work: --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org


如何离线安装软件包?

问题:如何离线安装软件包?

从pypi下载python软件包的最佳方法是什么,以便从另一台计算机上脱机安装?有什么简单的方法可以通过pip或easy_install来做到这一点?我正在尝试在未连接到Internet的FreeBSD盒上安装请求库。

What’s the best way to download a python package and it’s dependencies from pypi for offline installation on another machine? Is there any easy way to do this with pip or easy_install? I’m trying to install the requests library on a FreeBSD box that is not connected to the internet.


回答 0

如果该软件包位于PYPI上,则将其及其依赖项下载到某个本地目录。例如

$ mkdir / pypi && cd / pypi
$ ls -la
  -rw-r--r-- 1个Pavel人员237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz
  -rw-r--r-- 1个Pavel员工389741 2月22日17:10 Jinja2-2.6.tar.gz
  -rw-r--r-- 1个Pavel人员70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz
  -rw-r--r-- 1个Pavel人员2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz
  -rw-r--r-- 1个Pavel员工1108056 2月22日17:10 Werkzeug-0.8.2.tar.gz
  -rw-r--r-- 1个Pavel员工488207 Apr 10 18:26 boto-2.3.0.tar.gz
  -rw-r--r-- 1个Pavel人员490192 4月16日12:00 flask-0.9-dev-2a6c80a.tar.gz

某些软件包可能必须手工存档到外观相似的tarball中。当我想要某个东西的最新版本(不稳定)时,我会做很多事情。某些软件包不在PYPI上,因此也适用于它们。

假设您在中有一个格式正确的Python应用程序~/src/myapp~/src/myapp/setup.py将会install_requires列出您/pypi目录中的一或多个内容的列表。像这样:

  install_requires=[
    'boto',
    'Flask',
    'Werkzeug',
    # and so on

如果您希望能够在拥有所有必要依赖项的情况下运行您的应用程序,同时仍然对其进行黑客攻击,则可以执行以下操作:

$ cd〜/ src / myapp
$ python setup.py开发--always-unzip --allow-hosts = None --find-links = / pypi

这样,您的应用将直接从您的源目录执行。您可以破解某些东西,然后重新运行该应用程序而无需重建任何内容。

如果要将应用程序及其依赖项安装到当前的python环境中,请执行以下操作:

$ cd〜/ src / myapp
$ easy_install --always-unzip --allow-hosts = None --find-links = / pypi。

在这两种情况下,如果/pypi目录中不存在一个或多个依赖项,构建都将失败。它不会尝试从Internet混杂地安装丢失的东西。

我强烈建议在活动的虚拟环境中调用它setup.py develop ...,以避免污染全局Python环境。(virtualenv是)几乎可以走的路。切勿在全局Python环境中安装任何东西。easy_install ...

如果您构建了应用程序的计算机与要在其上部署应用程序的计算机具有相同的体系结构,则可以将所有easy_install内容都放入其中的整个虚拟环境目录中。不过,在压缩之前,您必须使虚拟环境目录可重定位(请参见 –relocatable选项)。注意:目标计算机需要安装相同版本的Python,并且应用程序可能也已经预安装了基于C的任何依赖关系(例如,如果您依赖PIL,那么必须预安装libpng,libjpeg等) 。

If the package is on PYPI, download it and its dependencies to some local directory. E.g.

$ mkdir /pypi && cd /pypi
$ ls -la
  -rw-r--r--   1 pavel  staff   237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz
  -rw-r--r--   1 pavel  staff   389741 Feb 22 17:10 Jinja2-2.6.tar.gz
  -rw-r--r--   1 pavel  staff    70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz
  -rw-r--r--   1 pavel  staff  2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz
  -rw-r--r--   1 pavel  staff  1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz
  -rw-r--r--   1 pavel  staff   488207 Apr 10 18:26 boto-2.3.0.tar.gz
  -rw-r--r--   1 pavel  staff   490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz

Some packages may have to be archived into similar looking tarballs by hand. I do it a lot when I want a more recent (less stable) version of something. Some packages aren’t on PYPI, so same applies to them.

Suppose you have a properly formed Python application in ~/src/myapp. ~/src/myapp/setup.py will have install_requires list that mentions one or more things that you have in your /pypi directory. Like so:

  install_requires=[
    'boto',
    'Flask',
    'Werkzeug',
    # and so on

If you want to be able to run your app with all the necessary dependencies while still hacking on it, you’ll do something like this:

$ cd ~/src/myapp
$ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi

This way your app will be executed straight from your source directory. You can hack on things, and then rerun the app without rebuilding anything.

If you want to install your app and its dependencies into the current python environment, you’ll do something like this:

$ cd ~/src/myapp
$ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .

In both cases, the build will fail if one or more dependencies aren’t present in /pypi directory. It won’t attempt to promiscuously install missing things from Internet.

I highly recommend to invoke setup.py develop ... and easy_install ... within an active virtual environment to avoid contaminating your global Python environment. It is (virtualenv that is) pretty much the way to go. Never install anything into global Python environment.

If the machine that you’ve built your app has same architecture as the machine on which you want to deploy it, you can simply tarball the entire virtual environment directory into which you easy_install-ed everything. Just before tarballing though, you must make the virtual environment directory relocatable (see –relocatable option). NOTE: the destination machine needs to have the same version of Python installed, and also any C-based dependencies your app may have must be preinstalled there too (e.g. say if you depend on PIL, then libpng, libjpeg, etc must be preinstalled).


回答 1

pip download命令使您无需安装即可下载软件包:

pip download -r requirements.txt

(在以前的pip版本中,拼写为 pip install --download -r requirements.txt。)

然后,您可以使用它们pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt来安装那些下载的sdist,而无需访问网络。

The pip download command lets you download packages without installing them:

pip download -r requirements.txt

(In previous versions of pip, this was spelled pip install --download -r requirements.txt.)

Then you can use pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt to install those downloaded sdists, without accessing the network.


回答 2

如果要脱机安装python库及其依赖项,请在具有相同操作系统,网络连接和python安装的机器上完成以下步骤:

1)创建一个requirements.txt内容相似的文件(注意-这些是您要下载的库):

Flask==0.12
requests>=2.7.0
scikit-learn==0.19.1
numpy==1.14.3
pandas==0.22.0

创建需求文件的一种方法是使用pip freeze > requirements.txt。这将列出您环境中的所有库。那你可以进去requirements.txt并删除不需要的对象。

2)执行命令 mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse以将库及其依赖项下载到目录wheelhouse

3)将requirements.txt复制到 wheelhouse目录中

4)存档驾驶室成wheelhouse.tar.gztar -zcf wheelhouse.tar.gz wheelhouse

然后上传wheelhouse.tar.gz到目标计算机:

1)执行tar -zxf wheelhouse.tar.gz以提取文件

2)执行pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse以安装库及其依赖项

If you want install python libs and their dependencies offline, finish following these steps on a machine with the same os, network connected, and python installed:

1) Create a requirements.txt file with similar content (Note – these are the libraries you wish to download):

Flask==0.12
requests>=2.7.0
scikit-learn==0.19.1
numpy==1.14.3
pandas==0.22.0

One option for creating the requirements file is to use pip freeze > requirements.txt. This will list all libraries in your environment. Then you can go in to requirements.txt and remove un-needed ones.

2) Execute command mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse to download libs and their dependencies to directory wheelhouse

3) Copy requirements.txt into wheelhouse directory

4) Archive wheelhouse into wheelhouse.tar.gz with tar -zcf wheelhouse.tar.gz wheelhouse

Then upload wheelhouse.tar.gz to your target machine:

1) Execute tar -zxf wheelhouse.tar.gz to extract the files

2) Execute pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse to install the libs and their dependencies


回答 3

离线python。为此,我使用virtualenv(隔离的Python环境)

1)使用pip在线安装virtualenv:

pip install virtualenv --user

或使用whl脱机:转到此链接,下载最新版本(.whl或tar.gz),然后使用以下命令进行安装:

pip install virtualenv-15.1.0-py2.py3-none-any.whl --user

通过使用--user您不需要使用sudo pip…

2)使用virtualenv

在联机计算机上,选择带有终端的目录cd并运行以下代码:

python -m virtualenv myenv
cd myenv
source bin/activate
pip install Flask

安装所有软件包后,必须requirements.txt在virtualenv处于活动状态时生成一个,以便

pip freeze > requirements.txt

打开一个新终端并创建另一个env之类的myenv2

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
ls

现在,您可以转到您的requirements.txttranferred_packages文件夹所在的脱机文件夹。使用以下代码下载软件包,并将其全部放入tranferred_packages文件夹。

pip download -r requirements.txt

将您的脱机文件夹移至脱机计算机,然后

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
cd offline
pip install --no-index --find-links="./tranferred_packages" -r requirements.txt

离线文件夹中的内容[requirements.txt,tranferred_pa​​ckages {Flask-0.10.1.tar.gz,…}]

检查包裹清单

pip list

注意:与2017年一样,最好使用python3。您可以使用此命令创建python 3 virtualenv。

virtualenv -p python3 envname

offline python. for doing this I use virtualenv (isolated Python environment)

1) install virtualenv online with pip:

pip install virtualenv --user

or offline with whl: go to this link , download last version (.whl or tar.gz) and install that with this command:

pip install virtualenv-15.1.0-py2.py3-none-any.whl --user

by using --user you don’t need to use sudo pip….

2) use virtualenv

on online machine select a directory with terminal cd and run this code:

python -m virtualenv myenv
cd myenv
source bin/activate
pip install Flask

after installing all the packages, you have to generate a requirements.txt so while your virtualenv is active, write

pip freeze > requirements.txt

open a new terminal and create another env like myenv2.

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
ls

now you can go to your offline folder where your requirements.txt and tranferred_packages folder are in there. download the packages with following code and put all of them to tranferred_packages folder.

pip download -r requirements.txt

take your offline folder to offline computer and then

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
cd offline
pip install --no-index --find-links="./tranferred_packages" -r requirements.txt

what is in the folder offline [requirements.txt , tranferred_packages {Flask-0.10.1.tar.gz, …}]

check list of your package

pip list

note: as we are in 2017 it is better to use python 3. you can create python 3 virtualenv with this command.

virtualenv -p python3 envname

回答 4

下载压缩包,将其转移到您的FreeBSD机器上并解压缩,然后运行python setup.py install就可以了!

编辑:只是要补充一点,您现在也可以使用pip安装tarball。

Download the tarball, transfer it to your FreeBSD machine and extract it, afterwards run python setup.py install and you’re done!

EDIT: Just to add on that, you can also install the tarballs with pip now.


回答 5

让我一步一步地完成该过程:

  1. 在连接到互联网的计算机上,创建一个文件夹。
   $ mkdir packages
   $ cd packages
  1. 打开命令提示符或shell并执行以下命令:

    假设您想要的软件包是 tensorflow

    $ pip download tensorflow

  2. 现在,在目标计算机上,复制packages文件夹并应用以下命令

  $ cd packages
  $ pip install 'tensorflow-xyz.whl' --no-index --find-links '.'

请注意,tensorflow-xyz.whl必须将替换为所需软件包的原始名称。

Let me go through the process step by step:

  1. On a computer connected to the internet, create a folder.
   $ mkdir packages
   $ cd packages
  1. open up a command prompt or shell and execute the following command:

    Suppose the package you want is tensorflow

    $ pip download tensorflow

  2. Now, on the target computer, copy the packages folder and apply the following command

  $ cd packages
  $ pip install 'tensorflow-xyz.whl' --no-index --find-links '.'

Note that the tensorflow-xyz.whl must be replaced by the original name of the required package.


回答 6

使用wheel编译包。

打包:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

复制tarball并安装:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*

注意wheel二进制软件包不是跨机器的。

更多参考 此处:https : //pip.pypa.io/en/stable/user_guide/#installation-bundles

Using wheel compiled packages.

bundle up:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

copy tarball and install:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*

Note wheel binary packages are not across machines.

More ref. here: https://pip.pypa.io/en/stable/user_guide/#installation-bundles


回答 7

我有一个类似的问题。而且我必须以相同的方式安装它,我们是从pypi安装的。

我做了以下事情:

  1. 创建一个目录以存储机器中所有可以访问Internet的软件包。

    mkdir -p /path/to/packages/
  2. 将所有软件包下载到路径

    pip download -r requirements.txt -d /path/to/packages
    
    Eg:- ls /root/wheelhouse/  # **/root/wheelhouse** is my **/path/to/packages/**
    total 4524
    -rw-r--r--. 1 root root   16667 May 23  2017 incremental-17.5.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   34713 Sep  1 10:21 attrs-18.2.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root 3088398 Oct 15 14:41 Twisted-18.9.0.tar.bz2
    -rw-r--r--. 1 root root  133356 Jan 28 15:58 chardet-3.0.4-py2.py3-none-any.whl
    -rw-r--r--. 1 root root  154154 Jan 28 15:58 certifi-2018.11.29-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   57987 Jan 28 15:58 requests-2.21.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   58594 Jan 28 15:58 idna-2.8-py2.py3-none-any.whl
    -rw-r--r--. 1 root root  118086 Jan 28 15:59 urllib3-1.24.1-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   47229 Jan 28 15:59 tqdm-4.30.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root    7922 Jan 28 16:13 constantly-15.1.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root  164706 Jan 28 16:14 zope.interface-4.6.0-cp27-cp27mu-manylinux1_x86_64.whl
    -rw-r--r--. 1 root root  573841 Jan 28 16:14 setuptools-40.7.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   37638 Jan 28 16:15 Automat-0.7.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   37905 Jan 28 16:15 hyperlink-18.0.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   52311 Jan 28 16:15 PyHamcrest-1.9.0-py2.py3-none-any.whl
    -rw-r--r--. 1 root root   10586 Jan 28 16:15 six-1.12.0-py2.py3-none-any.whl
  3. 压缩软件包目录,然后将其复制到没有Internet访问权限的计算机上。然后做,

    cd /path/to/packages/
    tar -cvzf packages.tar.gz .  # not the . (dot) at the end

    packages.tar.gz复制到没有Internet访问权限的目标计算机中。

  4. 在无法访问互联网的计算机上,执行以下操作(假设您将已解压缩的软件包复制到当前计算机上的/ path / to / package /中)

    cd /path/to/packages/
    tar -xvzf packages.tar.gz
    mkdir -p $HOME/.config/pip/
    
    vi $HOME/.config/pip/pip.conf

    并将以下内容粘贴并保存。

    [global]
    timeout = 10
    find-links = file:///path/to/package/
    no-cache-dir = true
    no-index = true
  5. 最后,我建议您使用某种形式的virtualenv安装软件包。

    virtualenv -p python2 venv # use python3, if you are on python3
    source ./venv/bin/activate
    pip install <package>

您应该能够下载目录/ path / to / package /中的所有模块。

注意:我只是这样做,因为我无法添加选项或更改我们安装模块的方式。不然我会做的

    pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt

I had a similar problem. And i had to make it install the same way, we do from pypi.

I did the following things:

  1. Make a directory to store all the packages in the machine that have internet access.

    mkdir -p /path/to/packages/
    
  2. Download all the packages to the path

Edit: You can also try:

python3 -m pip wheel --no-cache-dir -r requirements.txt -w /path/to/packages
pip download -r requirements.txt -d /path/to/packages

Eg:- ls /root/wheelhouse/  # **/root/wheelhouse** is my **/path/to/packages/**
total 4524
-rw-r--r--. 1 root root   16667 May 23  2017 incremental-17.5.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   34713 Sep  1 10:21 attrs-18.2.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 3088398 Oct 15 14:41 Twisted-18.9.0.tar.bz2
-rw-r--r--. 1 root root  133356 Jan 28 15:58 chardet-3.0.4-py2.py3-none-any.whl
-rw-r--r--. 1 root root  154154 Jan 28 15:58 certifi-2018.11.29-py2.py3-none-any.whl
-rw-r--r--. 1 root root   57987 Jan 28 15:58 requests-2.21.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   58594 Jan 28 15:58 idna-2.8-py2.py3-none-any.whl
-rw-r--r--. 1 root root  118086 Jan 28 15:59 urllib3-1.24.1-py2.py3-none-any.whl
-rw-r--r--. 1 root root   47229 Jan 28 15:59 tqdm-4.30.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root    7922 Jan 28 16:13 constantly-15.1.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  164706 Jan 28 16:14 zope.interface-4.6.0-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r--. 1 root root  573841 Jan 28 16:14 setuptools-40.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   37638 Jan 28 16:15 Automat-0.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   37905 Jan 28 16:15 hyperlink-18.0.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   52311 Jan 28 16:15 PyHamcrest-1.9.0-py2.py3-none-any.whl
 -rw-r--r--. 1 root root   10586 Jan 28 16:15 six-1.12.0-py2.py3-none-any.whl
  1. Tar the packages directory and copy it to the Machine that doesn’t have internet access. Then do,

    cd /path/to/packages/
    tar -cvzf packages.tar.gz .  # not the . (dot) at the end
    

Copy the packages.tar.gz into the destination machine that doesn’t have internet access.

  1. In the machine that doesn’t have internet access, do the following (Assuming you copied the tarred packages to /path/to/package/ in the current machine)

    cd /path/to/packages/
    tar -xvzf packages.tar.gz
    mkdir -p $HOME/.config/pip/
    vi $HOME/.config/pip/pip.conf
    

and paste the following content inside and save it.

[global]
timeout = 10
find-links = file:///path/to/package/
no-cache-dir = true
no-index = true
  1. Finally, i suggest you use, some form of virtualenv for installing the packages.

    virtualenv -p python2 venv # use python3, if you are on python3
    source ./venv/bin/activate
    pip install <package>
    

You should be able to download all the modules that are in the directory /path/to/package/.

Note: I only did this, because i couldn’t add options or change the way we install the modules. Otherwise i’d have done

pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt

回答 8

对于Pip 8.1.2,您可以用于pip download -r requ.txt将软件包下载到本地计算机。

For Pip 8.1.2 you can use pip download -r requ.txt to download packages to your local machine.


ImportError:没有名为PIL的模块

问题:ImportError:没有名为PIL的模块

我在外壳中使用以下命令来安装PIL:

easy_install PIL

然后我运行python,并输入:import PIL。但是我得到这个错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named PIL

我从来没有遇到过这样的问题,您怎么看?

I use this command in the shell to install PIL:

easy_install PIL

then I run python and type this: import PIL. But I get this error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named PIL

I’ve never had such problem, what do you think?


回答 0

在某些PIL安装中,您必须执行

import Image

而不是import PIL(实际上并非总是以这种方式导入PIL)。由于import Image对您有用,因此实际上您已经安装了PIL。

为库和Python模块使用不同的名称是不寻常的,但这是为PIL(某些版本)选择的。

您可以从官方教程中获得有关如何使用此模块的更多信息。

PS:实际上,在某些安装上import PIL 确实可以工作,这增加了混乱。这可以通过@JanneKarila发现的文档中示例以及MacPorts PIL软件包的某些最新版本(1.1.7)加以确认。

On some installs of PIL, You must do

import Image

instead of import PIL (PIL is in fact not always imported this way). Since import Image works for you, this means that you have in fact installed PIL.

Having a different name for the library and the Python module is unusual, but this is what was chosen for (some versions of) PIL.

You can get more information about how to use this module from the official tutorial.

PS: In fact, on some installs, import PIL does work, which adds to the confusion. This is confirmed by an example from the documentation, as @JanneKarila found out, and also by some more recent versions of the MacPorts PIL package (1.1.7).


回答 1

在外壳中,运行:

pip install Pillow

注意:已弃用PIL,后继枕头

In shell, run:

pip install Pillow

Attention: PIL is deprecated, and pillow is the successor.


回答 2

另一方面,我强烈建议您使用与PIL向后兼容并且可以更好地维护/在较新的系统上使用的Pillow

安装后即可

import PIL 

要么

from PIL import Image

等等..

On a different note, I can highly recommend the use of Pillow which is backwards compatible with PIL and is better maintained/will work on newer systems.

When that is installed you can do

import PIL 

or

from PIL import Image

etc..


回答 3

首先安装枕头

pip install Pillow

或如下

c:\Python35>python -m pip install Pillow

然后在python代码中,您可以调用

from PIL import Image

“ Pillow是PIL(Python映像库)的一个分支,不再维护。但是,为了保持向后兼容性,将使用旧的模块名称。” 从枕头安装,但“没有模块命名为枕头”-python2.7-Windows 7-python -m安装枕头

At first install Pillow with

pip install Pillow

or as follows

c:\Python35>python -m pip install Pillow

Then in python code you may call

from PIL import Image

“Pillow is a fork of PIL, the Python Imaging Library, which is no longer maintained. However, to maintain backwards compatibility, the old module name is used.” From pillow installed, but “no module named pillow” – python2.7 – Windows 7 – python -m install pillow


回答 4

有时我会在python中运行Unitest时遇到此类错误。解决方案是在虚拟环境中卸载并安装相同的软件包。

使用此命令:

pip uninstall PIL

pip install  PIL 

如果由于任何原因出现错误,请在命令开头添加sudo,然后按Enter键输入密码。

Sometimes I get this type of error running a Unitest in python. The solution is to uninstall and install the same package on your virtual environment.

Using this commands:

pip uninstall PIL

and

pip install  PIL 

If for any reason you get an error, add sudo at the beginning of the command and after hitting enter type your password.


回答 5

这在Ubuntu 16.04上对我有用:

sudo apt-get install python-imaging

经过大约半小时的搜索,我在Wikibooks上找到了它。

This worked for me on Ubuntu 16.04:

sudo apt-get install python-imaging

I found this on Wikibooks after searching for about half an hour.


回答 6

我用了:

pip install Pillow 

和pip在Lib \ site-packages中安装了PIL。当我将PIL移至Lib时,一切正常。我在Windows 10上。

I used:

pip install Pillow 

and pip installed PIL in Lib\site-packages. When I moved PIL to Lib everything worked fine. I’m on Windows 10.


回答 7

在Windows 10上,我设法达到了:

cd "C:\Users\<your username>\AppData\Local\Programs\Python\Python37-32" 
python -m pip install --upgrade pip     <-- upgrading from 10.something to 19.2.2.
pip3 uninstall pillow
pip3 uninstall PIL
pip3 install image

之后在python中(在我的情况下是python 3.7),这很好用…

import PIL
from PIL import image

On windows 10 I managed to get there with:

cd "C:\Users\<your username>\AppData\Local\Programs\Python\Python37-32" 
python -m pip install --upgrade pip     <-- upgrading from 10.something to 19.2.2.
pip3 uninstall pillow
pip3 uninstall PIL
pip3 install image

after which in python (python 3.7 in my case) this works fine…

import PIL
from PIL import image

回答 8

您必须使用python软件包安装Image和pillow。

类型

python -m pip install image 

或运行命令提示符(在Windows中),然后导航到scripts文件夹

cd C:\Python27\Scripts

然后在命令下面运行

pip install image

you have to install Image and pillow with your python package.

type

python -m pip install image 

or run command prompt (in windows), then navigate to the scripts folder

cd C:\Python27\Scripts

then run below command

pip install image

回答 9

如果您使用水蟒:

conda install pillow

if you use anaconda:

conda install pillow

回答 10

在Windows上,尝试检查PIL库位置的路径。在我的系统上,我注意到路径是

\Python26\Lib\site-packages\pil instead of \Python26\Lib\site-packages\PIL  

pil文件夹重命名为后PIL,我可以加载PIL模块。

On windows, try checking the path to the location of the PIL library. On my system, I noticed the path was

\Python26\Lib\site-packages\pil instead of \Python26\Lib\site-packages\PIL  

after renaming the pil folder to PIL, I was able to load the PIL module.


回答 11

您将需要使用python软件包安装Image和pillow。放心,命令行将为您处理一切。

击中

python -m pip安装映像

You will need to install Image and pillow with your python package. Rest assured, the command line will take care of everything for you.

Hit

python -m pip install image


回答 12

而不是PIL使用枕头它有效

easy_install Pillow

要么

pip install Pillow

instead of PIL use Pillow it works

easy_install Pillow

or

pip install Pillow

回答 13

在Windows上,您需要下载并安装.exe

https://pypi.python.org/pypi/Pillow/2.7.0

On Windows, you need to download it and install the .exe

https://pypi.python.org/pypi/Pillow/2.7.0


回答 14

我使用conda-forge安装了枕头版本5,这似乎对我有用:

conda install --channel conda-forge pillow=5

普通的conda安装枕头对我不起作用。

I used conda-forge to install pillow version 5, and that seemed to work for me:

conda install --channel conda-forge pillow=5

the normal conda install pillow did NOT work for me.


回答 15

导入PIL并进一步导入ImageTk和Image模块时,我遇到了相同的问题。我也尝试直接通过pip安装PIL。但无法成功。由于介于两者之间,因此已建议不要使用PIL,因此,尝试仅通过点子安装枕头。枕头已成功安装,此外,PIL软件包位于以下路径中:python27 / Lib / site-packages /。

现在可以导入Image和ImageTk。

I had the same issue while importing PIL and further importing the ImageTk and Image modules. I also tried installing PIL directly through pip. but not success could be achieved. As in between it has been suggested that PIL has been deprectaed, thus, tried to install pillow through pip only. pillow was successfully installed, further, the PIL package was made under the path : python27/Lib/site-packages/.

Now both Image and ImageTk could be imported.


回答 16

我最近安装了Leap。我尝试了openshot,但没有开始。于是来到这里,发现了一个建议从终端开始,看看是否有任何错误。

我的错误是error missing mlt。所以我python-mlt从Yast 安装了模块并导入了它,尝试启动,但是下一个openshot说missing pil.

我按照枕头建议安装,因为Yast找不到任何pil和导入的pil。没关系,但没有开始显示Error missing goocanvas

我安装goocanvas了Yast,用python导入了它,然后Openshot启动了!

随着大量的终端这样的错误的missing Vimeoclient和大量的attributeerrors。好吧,看看是否有任何影响。

I recently installed Leap. I Tried openshot and it didn’t start. So came here and found a suggestion to start from the Terminal to see if there were any error.

The error I had was error missing mlt. So I installed the python-mlt module from Yast and imported it, tried to start but next openshot said missing pil.

I Followed the Pillow suggestion to install because Yast couldn’t find any pil and imported pil. That went ok but did not start and showed Error missing goocanvas.

The I installed goocanvas with Yast, imported it in python, and Openshot fired up !!

With a lot of errors in the terminal like missing Vimeoclient and lots of attributeerrors. Well, will see if it is of any influence working with it.


回答 17

我遇到了同样的问题,我通过检查pip(pip3 --version)是什么版本来解决了这个问题,然后意识到我输入的python<uncorrect version> filename.py不是python<correct version> filename.py

I had the same problem and i fixed it by checking what version pip (pip3 --version) is, then realizing I’m typing python<uncorrect version> filename.py instead of python<correct version> filename.py


回答 18

您可能缺少构建pil的python标头。如果您使用的是ubuntu或类似功能,它将类似于

apt-get install python-dev

You are probably missing the python headers to build pil. If you’re using ubuntu or the likes it’ll be something like

apt-get install python-dev

dist-packages和site-packages有什么区别?

问题:dist-packages和site-packages有什么区别?

我对python软件包的安装过程有些不满意。具体来说,安装在dist-packages目录和site-packages目录中的软件包之间有什么区别?

I’m a bit miffed by the python package installation process. Specifically, what’s the difference between packages installed in the dist-packages directory and the site-packages directory?


回答 0

dist-packages是特定于Debian的约定,也存在于其衍生版本中,例如Ubuntu。当模块从Debian软件包管理器进入以下位置时,它们将安装到dist-packages中:

/usr/lib/python2.7/dist-packages

由于easy_installpip是从软件包管理器安装的,因此它们也使用dist-packages,但是它们将软件包放在此处:

/usr/local/lib/python2.7/dist-packages

Debian Python Wiki

dist-packages而不是site-packages。从Debian软件包安装的第三方Python软件进入dist软件包,而不是站点软件包。这是为了减少系统Python与您可能手动安装的任何源Python构建之间的冲突。

这意味着,如果您从源代码手动安装Python,它将使用site-packages目录。这使您可以将两个安装分开,特别是因为Debian和Ubuntu在许多系统实用程序中都依赖Python的系统版本。

dist-packages is a Debian-specific convention that is also present in its derivatives, like Ubuntu. Modules are installed to dist-packages when they come from the Debian package manager into this location:

/usr/lib/python2.7/dist-packages

Since easy_install and pip are installed from the package manager, they also use dist-packages, but they put packages here:

/usr/local/lib/python2.7/dist-packages

From the Debian Python Wiki:

dist-packages instead of site-packages. Third party Python software installed from Debian packages goes into dist-packages, not site-packages. This is to reduce conflict between the system Python, and any from-source Python build you might install manually.

This means that if you manually install Python from source, it uses the site-packages directory. This allows you to keep the two installations separate, especially since Debian and Ubuntu rely on the system version of Python for many system utilities.


回答 1

dist-packages是debian专用的目录,apt朋友可以在其中安装他们的东西,并且site-packages是标准pip目录。

问题是-当不同目录中存在相同软件包的不同版本时,会发生什么?

我对这个问题的解决方案是建立dist-packages一个符号链接到site-packages

for d in $(find $WORKON_HOME -type d -name dist-packages); do
  pushd $d
  cd ..
  if test -d dist-packages/__pycache__; then
    mv -v dist-packages/__pycache__/* site-packages/__pycache__/
    rmdir -v dist-packages/__pycache__
  fi
  mv -v dist-packages/* site-packages/
  rmdir -v dist-packages
  ln -sv site-packages dist-packages
  popd
done

(如果您不使用gnu工具,请删除该-v选项)。

dist-packages is the debian-specific directory where apt and friends install their stuff, and site-packages is the standard pip directory.

The problem is — what happens when different versions of the same package are present in different directories?

My solution to the problem is to make dist-packages a symlink to site-packages:

for d in $(find $WORKON_HOME -type d -name dist-packages); do
  pushd $d
  cd ..
  if test -d dist-packages/__pycache__; then
    mv -v dist-packages/__pycache__/* site-packages/__pycache__/
    rmdir -v dist-packages/__pycache__
  fi
  mv -v dist-packages/* site-packages/
  rmdir -v dist-packages
  ln -sv site-packages dist-packages
  popd
done

(if you are not using gnu tools, remove the -v option).


如何在Ubuntu上安装LXML

问题:如何在Ubuntu上安装LXML

我在Ubuntu 11上使用easy_install安装lxml遇到困难。

当我输入时,$ easy_install lxml我得到:

Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3
Downloading http://lxml.de/files/lxml-2.3.tgz
Processing lxml-2.3.tgz
Running lxml-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7UdQOZ/lxml-2.3/egg-dist-tmp-GacQGy
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt 
In file included from src/lxml/lxml.etree.c:227:0:
src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory
compilation terminated.

看来libxslt还是libxml2没有安装。我已经尝试按照http://www.techsww.com/tutorials/libraries/libxslt/installation/installing_libxslt_on_ubuntu_linux.phphttp://www.techsww.com/tutorials/libraries/libxml/installation/installing_installing_libxml_on_ubuntu_linux上的说明进行操作。 PHP没有成功。

如果我尝试wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.6.27.tar.gz我会得到

<successful connection info>
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /libxml2 ... done.
==> SIZE libxml2-sources-2.6.27.tar.gz ... done.
==> PASV ... done.    ==> RETR libxml2-sources-2.6.27.tar.gz ... 
No such file `libxml2-sources-2.6.27.tar.gz'.

如果我先尝试另一种,那我会做的,./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2最终会失败,并显示以下内容:

checking for libxml libraries >= 2.6.27... configure: error: Could not find libxml2 anywhere, check ftp://xmlsoft.org/.

我试过两个版本2.6.272.6.29libxml2没什么区别。

不遗余力,我已经成功完成了sudo apt-get install libxml2-dev,但这并没有改变。

I’m having difficulty installing lxml with easy_install on Ubuntu 11.

When I type $ easy_install lxml I get:

Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3
Downloading http://lxml.de/files/lxml-2.3.tgz
Processing lxml-2.3.tgz
Running lxml-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7UdQOZ/lxml-2.3/egg-dist-tmp-GacQGy
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt 
In file included from src/lxml/lxml.etree.c:227:0:
src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory
compilation terminated.

It seems that libxslt or libxml2 is not installed. I’ve tried following the instructions at http://www.techsww.com/tutorials/libraries/libxslt/installation/installing_libxslt_on_ubuntu_linux.php and http://www.techsww.com/tutorials/libraries/libxml/installation/installing_libxml_on_ubuntu_linux.php with no success.

If I try wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.6.27.tar.gz I get

<successful connection info>
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /libxml2 ... done.
==> SIZE libxml2-sources-2.6.27.tar.gz ... done.
==> PASV ... done.    ==> RETR libxml2-sources-2.6.27.tar.gz ... 
No such file `libxml2-sources-2.6.27.tar.gz'.

If I try the other first, I’ll get to ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2 and that will fail eventually with:

checking for libxml libraries >= 2.6.27... configure: error: Could not find libxml2 anywhere, check ftp://xmlsoft.org/.

I’ve tried both versions 2.6.27 and 2.6.29 of libxml2 with no difference.

Leaving no stone unturned, I have successfully done sudo apt-get install libxml2-dev, but this changes nothing.


回答 0

由于您使用的是Ubuntu,因此不必理会这些源代码包。只需使用apt-get安装这些开发包。

apt-get install libxml2-dev libxslt1-dev python-dev

但是,如果您对可能是旧版本的lxml感到满意,则可以尝试

apt-get install python-lxml

并完成它。:)

Since you’re on Ubuntu, don’t bother with those source packages. Just install those development packages using apt-get.

apt-get install libxml2-dev libxslt1-dev python-dev

If you’re happy with a possibly older version of lxml altogether though, you could try

apt-get install python-lxml

and be done with it. :)


回答 1

在lxml编译之前,我还必须安装lib32z1-dev(Ubuntu 13.04 x64)。

sudo apt-get install lib32z1-dev

或所有必需的包装在一起:

sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev

I also had to install lib32z1-dev before lxml would compile (Ubuntu 13.04 x64).

sudo apt-get install lib32z1-dev

Or all the required packages together:

sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev

回答 2

正如@Pepijn在ubuntu 13.04 x64上评论@Druska的答案一样,无需使用lib32z1-dev,zlib1g-dev就足够了:

sudo apt-get install libxml2-dev libxslt-dev python-dev zlib1g-dev

As @Pepijn commented on @Druska ‘s answer, on ubuntu 13.04 x64, there is no need to use lib32z1-dev, zlib1g-dev is enough:

sudo apt-get install libxml2-dev libxslt-dev python-dev zlib1g-dev

回答 3

我使用Ubuntu 14.04在Vagrant中使用pip安装了lxml,并且遇到了同样的问题。即使安装了所有要求,我也一次又一次遇到相同的错误。事实证明,默认情况下,我的VM的内存很少。有了1024 MB,一切正常。

将此添加到您的VagrantFile中,lxml应该正确编译/安装:

config.vm.provider "virtualbox" do |vb|
  vb.memory = 1024
end

感谢sixhobbit的提示(请参阅:无法在Ubuntu 12.04上安装lxml)。

I installed lxml with pip in Vagrant, using Ubuntu 14.04 and had the same problem. Even though all requirements where installed, i got the same error again and again. Turned out, my VM had to little memory by default. With 1024 MB everything works fine.

Add this to your VagrantFile and lxml should properly compile / install:

config.vm.provider "virtualbox" do |vb|
  vb.memory = 1024
end

Thanks to sixhobbit for the hint (see: can’t installing lxml on Ubuntu 12.04).


回答 4

对于Ubuntu 14.04

sudo apt-get install python-lxml

为我工作。

For Ubuntu 14.04

sudo apt-get install python-lxml

worked for me.


回答 5

步骤1

使用此命令安装最新的python更新。

sudo apt-get install python-dev

第2步

添加第一个依赖项libxml2版本2.7.0或更高版本

sudo apt-get install libxml2-dev

第三步

添加第二个依赖库libxslt版本1.1.23或更高版本

sudo apt-get install libxslt1-dev

第四步

首先安装pip软件包管理工具。并运行此命令。

pip install lxml

如果您有任何疑问,请点击这里

Step 1

Install latest python updates using this command.

sudo apt-get install python-dev

Step 2

Add first dependency libxml2 version 2.7.0 or later

sudo apt-get install libxml2-dev

Step 3

Add second dependency libxslt version 1.1.23 or later

sudo apt-get install libxslt1-dev

Step 4

Install pip package management tool first. and run this command.

pip install lxml

If you have any doubt Click Here


回答 6

安装AKX提到的软件包后,我仍然遇到相同的问题。解决了

apt-get install python-dev

After installing the packages mentioned by AKX I still had the same problem. Solved it with

apt-get install python-dev

回答 7

对于Ubuntu 12.04.3 LTS(精确的穿山甲),我必须这样做:

apt-get install libxml2-dev libxslt1-dev

(注意libxslt1-dev中的“ 1”)

然后我刚刚用pip / easy_install安装了lxml。

For Ubuntu 12.04.3 LTS (Precise Pangolin) I had to do:

apt-get install libxml2-dev libxslt1-dev

(Note the “1” in libxslt1-dev)

Then I just installed lxml with pip/easy_install.


回答 8

从Ubuntu 18.4(Bionic Beaver)开始,建议使用apt而不是apt-get,因为它具有更好的结构形式。

sudo apt install libxml2-dev libxslt1-dev python-dev

如果您对可能是旧版本的设备感到满意lxml,则可以尝试

sudo apt install python-lxml

From Ubuntu 18.4 (Bionic Beaver) it is advisable to use apt instead of apt-get since it has much better structural form.

sudo apt install libxml2-dev libxslt1-dev python-dev

If you’re happy with a possibly older version of lxml altogether though, you could try

sudo apt install python-lxml

回答 9


由于@Simplans(https://stackoverflow.com/a/37759871/417747)的指针和主页,这里的许多答案都比较旧了。

什么对我有用(Ubuntu仿生):

sudo apt-get install python3-lxml  

(+ sudo apt-get install libxml2-dev libxslt1-dev我已经安装了它,但是不确定那是否仍然是必需的)

Many answers here are rather old,
thanks to the pointer from @Simplans (https://stackoverflow.com/a/37759871/417747) and the home page

What worked for me (Ubuntu bionic):

sudo apt-get install python3-lxml  

(+ sudo apt-get install libxml2-dev libxslt1-dev I installed before it, but not sure if that’s the requirement still)


回答 10

首先安装Ubuntu的python-lxml软件包及其依赖项:

sudo apt-get install python-lxml

然后使用pip升级到适用于Python的lxml的最新版本:

pip install lxml

First install Ubuntu’s python-lxml package and its dependencies:

sudo apt-get install python-lxml

Then use pip to upgrade to the latest version of lxml for Python:

pip install lxml

查找使用easy_install / pip安装的所有软件包?

问题:查找使用easy_install / pip安装的所有软件包?

有没有办法找到所有通过easy_install或pip安装的Python PyPI软件包?我的意思是,排除分发工具已经安装的所有东西(在本例中为Debian上的apt-get)。

Is there a way to find all Python PyPI packages that were installed with easy_install or pip? I mean, excluding everything that was/is installed with the distributions tools (in this case apt-get on Debian).


回答 0

pip freeze将输出已安装软件包及其版本的列表。它还允许您将那些程序包写入文件,以便以后用于设置新环境。

https://pip.pypa.io/zh_CN/stable/reference/pip_freeze/#pip-freeze

pip freeze will output a list of installed packages and their versions. It also allows you to write those packages to a file that can later be used to set up a new environment.

https://pip.pypa.io/en/stable/reference/pip_freeze/#pip-freeze


回答 1

从1.3版本的pip开始,您现在可以使用 pip list

它具有一些有用的选项,包括显示过期软件包的能力。这是文档:https : //pip.pypa.io/en/latest/reference/pip_list/

As of version 1.3 of pip you can now use pip list

It has some useful options including the ability to show outdated packages. Here’s the documentation: https://pip.pypa.io/en/latest/reference/pip_list/


回答 2

如果有人想知道您可以使用“ pip show”命令。

pip show [options] <package>

这将列出给定软件包的安装目录。

If anyone is wondering you can use the ‘pip show’ command.

pip show [options] <package>

This will list the install directory of the given package.


回答 3

如果Debian在pip install默认目标上的行为类似于最近的Ubuntu版本,那就太简单了:它安装到(/usr/local/lib/而不是/usr/libapt默认目标))。检查/ubuntu/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747

我是ArchLinux用户,在尝试pip时遇到了同样的问题。这是我在Arch中解决问题的方法。

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs pacman -Qo | grep 'No package'

此处的关键是/usr/lib/python2.7/site-packages,这是pip安装到的目录YMMV。pacman -Qo是如何Arch的PAC卡格男人几岁检查该文件的所有权。No package是没有包拥有文件时返回的一部分error: No package owns $FILENAME。整蛊解决方法:我询问有关__init__.py,因为pacman -Qo有点懵,当涉及到目录:(

为了在其他发行版中做到这一点,您必须找出在哪里pip安装东西(仅仅sudo pip install是东西),如何查询文件的所有权(Debian / Ubuntu方法是dpkg -S)以及“没有软件包拥有该路径”返回(Debian)是什么。 / Ubuntu是no path found matching pattern)。Debian / Ubuntu用户,请注意:dpkg -S如果给它一个符号链接,它将失败。只需先使用解决即可realpath。像这样:

find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | xargs dpkg -S 2>&1 | grep 'no path found'

Fedora用户可以尝试(感谢@eddygeek):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

If Debian behaves like recent Ubuntu versions regarding pip install default target, it’s dead easy: it installs to /usr/local/lib/ instead of /usr/lib (apt default target). Check https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747

I am an ArchLinux user and as I experimented with pip I met this same problem. Here’s how I solved it in Arch.

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs pacman -Qo | grep 'No package'

Key here is /usr/lib/python2.7/site-packages, which is the directory pip installs to, YMMV. pacman -Qo is how Arch’s pac kage man ager checks for ownership of the file. No package is part of the return it gives when no package owns the file: error: No package owns $FILENAME. Tricky workaround: I’m querying about __init__.py because pacman -Qo is a little bit ignorant when it comes to directories :(

In order to do it for other distros, you have to find out where pip installs stuff (just sudo pip install something), how to query ownership of a file (Debian/Ubuntu method is dpkg -S) and what is the “no package owns that path” return (Debian/Ubuntu is no path found matching pattern). Debian/Ubuntu users, beware: dpkg -S will fail if you give it a symbolic link. Just resolve it first by using realpath. Like this:

find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | xargs dpkg -S 2>&1 | grep 'no path found'

Fedora users can try (thanks @eddygeek):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

回答 4

从…开始:

$ pip list

列出所有软件包。找到所需的软件包后,请使用:

$ pip show <package-name>

这将显示有关此软件包的详细信息,包括其文件夹。如果您已经知道软件包名称,则可以跳过第一部分

点击这里对PIP显示更多的信息,这里的PIP列表的详细信息。

例:

$ pip show jupyter
Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires: ipywidgets, nbconvert, notebook, jupyter-console, qtconsole, ipykernel    

Start with:

$ pip list

To list all packages. Once you found the package you want, use:

$ pip show <package-name>

This will show you details about this package, including its folder. You can skip the first part if you already know the package name

Click here for more information on pip show and here for more information on pip list.

Example:

$ pip show jupyter
Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires: ipywidgets, nbconvert, notebook, jupyter-console, qtconsole, ipykernel    

回答 5

pip.get_installed_distributions() 将给出已安装软件包的列表

import pip
from os.path import join

for package in pip.get_installed_distributions():
    print(package.location) # you can exclude packages that's in /usr/XXX
    print(join(package.location, package._get_metadata("top_level.txt"))) # root directory of this package

pip.get_installed_distributions() will give a list of installed packages

import pip
from os.path import join

for package in pip.get_installed_distributions():
    print(package.location) # you can exclude packages that's in /usr/XXX
    print(join(package.location, package._get_metadata("top_level.txt"))) # root directory of this package

回答 6

下面的程序有点慢,但是它给出了一个可以识别的格式良好的软件包列表pip。也就是说,并不是所有的人都通过“ pip”安装的,但是所有的人都应该能够通过pip进行升级。

$ pip search . | egrep -B1 'INSTALLED|LATEST'

之所以慢,是因为它列出了整个pypi存储库的内容。我提交了一张票,建议pip list提供类似的功能,但效率更高。

样本输出:(将搜索限制为所有子集而不是“。”。)

$ pip search selenium | egrep -B1 'INSTALLED|LATEST'

selenium                  - Python bindings for Selenium
  INSTALLED: 2.24.0
  LATEST:    2.25.0
--
robotframework-selenium2library - Web testing library for Robot Framework
  INSTALLED: 1.0.1 (latest)
$

The below is a little slow, but it gives a nicely formatted list of packages that pip is aware of. That is to say, not all of them were installed “by” pip, but all of them should be able to be upgraded by pip.

$ pip search . | egrep -B1 'INSTALLED|LATEST'

The reason it is slow is that it lists the contents of the entire pypi repo. I filed a ticket suggesting pip list provide similar functionality but more efficiently.

Sample output: (restricted the search to a subset instead of ‘.’ for all.)

$ pip search selenium | egrep -B1 'INSTALLED|LATEST'

selenium                  - Python bindings for Selenium
  INSTALLED: 2.24.0
  LATEST:    2.25.0
--
robotframework-selenium2library - Web testing library for Robot Framework
  INSTALLED: 1.0.1 (latest)
$

回答 7

除了@Paul Woolcock的答案,

pip freeze > requirements.txt

将在当前位置的活动环境中创建一个包含所有已安装软件包以及已安装版本号的需求文件。跑步

pip install -r requirements.txt

将安装需求文件中指定的软件包。

Adding to @Paul Woolcock’s answer,

pip freeze > requirements.txt

will create a requirements file with all installed packages along with the installed version numbers in the active environment at the current location. Running

pip install -r requirements.txt

will install the packages specified in the requirements file.


回答 8

较新版本的pip可以通过pip list -lpip freeze -l--list)执行OP所需的操作。
在Debian上(至少),手册页对此没有明确说明,而我只是在假设该功能必须存在的情况下才发现了with pip list --help

最近有评论表明此功能在文档或现有答案中均不明显(尽管有人暗示),所以我认为应该发布。我本来希望以此作为评论,但我没有信誉点。

Newer versions of pip have the ability to do what the OP wants via pip list -l or pip freeze -l (--list).
On Debian (at least) the man page doesn’t make this clear, and I only discovered it – under the assumption that the feature must exist – with pip list --help.

There are recent comments that suggest this feature is not obvious in either the documentation or the existing answers (although hinted at by some), so I thought I should post. I would have preferred to do so as a comment, but I don’t have the reputation points.


回答 9

请注意,如果您的计算机上安装了多个版本的Python,则每个版本可能都有一些pip版本。

根据您的关联,您可能需要非常谨慎使用以下pip命令:

pip3 list 

在运行Python3.4的地方为我工作。简单使用pip list返回错误The program 'pip' is currently not installed. You can install it by typing: sudo apt-get install python-pip

Take note that if you have multiple versions of Python installed on your computer, you may have a few versions of pip associated with each.

Depending on your associations, you might need to be very cautious of what pip command you use:

pip3 list 

Worked for me, where I’m running Python3.4. Simply using pip list returned the error The program 'pip' is currently not installed. You can install it by typing: sudo apt-get install python-pip.


回答 10

正如@almenon指出的那样,这不再起作用,它也不是在代码中获取包信息的支持方式。以下引发异常:

import pip
installed_packages = dict([(package.project_name, package.version) 
                           for package in pip.get_installed_distributions()])

为此,您可以import pkg_resources。这是一个例子:

import pkg_resources
installed_packages = dict([(package.project_name, package.version)
                           for package in pkg_resources.working_set])

我上线了 v3.6.5

As @almenon pointed out, this no longer works and it is not the supported way to get package information in your code. The following raises an exception:

import pip
installed_packages = dict([(package.project_name, package.version) 
                           for package in pip.get_installed_distributions()])

To accomplish this, you can import pkg_resources. Here’s an example:

import pkg_resources
installed_packages = dict([(package.project_name, package.version)
                           for package in pkg_resources.working_set])

I’m on v3.6.5


回答 11

这是Fedora或其他rpm发行版的一线工具(基于@barraponto技巧):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

将此附加到上一个命令以获取更干净的输出:

 | sed -r 's:.*/(\w+)/__.*:\1:'

Here is the one-liner for fedora or other rpm distros (based on @barraponto tips):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

Append this to the previous command to get cleaner output:

 | sed -r 's:.*/(\w+)/__.*:\1:'

回答 12

获取site-packages/dist-packages/如果存在)所有文件/文件夹的名称,然后使用包管理器剥离通过软件包安装的文件/文件夹名称。

Get all file/folder names in site-packages/ (and dist-packages/ if it exists), and use your package manager to strip the ones that were installed via package.


回答 13

pip Frozen列出了所有已安装的软件包,即使不是通过pip / easy_install也是如此。在CentOs / Redhat上,找到了通过rpm安装的软件包。

pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.


回答 14

如果使用Anaconda python发行版,则可以使用以下conda list命令查看通过什么方法安装了什么:

user@pc:~ $ conda list
# packages in environment at /anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0            py36h2fc01ae_0
alabaster                 0.7.10           py36h174008c_0
amqp                      2.2.2                     <pip>
anaconda                  5.1.0                    py36_2
anaconda-client           1.6.9                    py36_0

要获取安装者pip(可能包括pip其自身)安装的条目:

user@pc:~ $ conda list | grep \<pip
amqp                      2.2.2                     <pip>
astroid                   1.6.2                     <pip>
billiard                  3.5.0.3                   <pip>
blinker                   1.4                       <pip>
ez-setup                  0.9                       <pip>
feedgenerator             1.9                       <pip>

当然,您可能只想选择第一列即可进行处理(pip如果需要,则除外):

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}'
amqp        
astroid
billiard
blinker
ez-setup
feedgenerator 

最后,您可以获取这些值并使用以下命令pip卸载所有这些值:

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}' | xargs pip uninstall -y

请注意,使用-y标记pip uninstall来避免必须确认删除。

If you use the Anaconda python distribution, you can use the conda list command to see what was installed by what method:

user@pc:~ $ conda list
# packages in environment at /anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0            py36h2fc01ae_0
alabaster                 0.7.10           py36h174008c_0
amqp                      2.2.2                     <pip>
anaconda                  5.1.0                    py36_2
anaconda-client           1.6.9                    py36_0

To grab the entries installed by pip (including possibly pip itself):

user@pc:~ $ conda list | grep \<pip
amqp                      2.2.2                     <pip>
astroid                   1.6.2                     <pip>
billiard                  3.5.0.3                   <pip>
blinker                   1.4                       <pip>
ez-setup                  0.9                       <pip>
feedgenerator             1.9                       <pip>

Of course you probably want to just select the first column, which you can do with (excluding pip if needed):

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}'
amqp        
astroid
billiard
blinker
ez-setup
feedgenerator 

Finally you can grab these values and pip uninstall all of them using the following:

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}' | xargs pip uninstall -y

Note the use of the -y flag for the pip uninstall to avoid having to give confirmation to delete.


回答 15

对于那些没有安装pip的人,我在github上找到了这个快速脚本(适用于Python 2.7.13):

import pkg_resources
distros = pkg_resources.AvailableDistributions()
for key in distros:
  print distros[key]

For those who don’t have pip installed, I found this quick script on github (works with Python 2.7.13):

import pkg_resources
distros = pkg_resources.AvailableDistributions()
for key in distros:
  print distros[key]

回答 16

点列表[选项]您可以在此处查看完整的参考

pip list [options] You can see the complete reference here


回答 17

至少对于Ubuntu(也许还有其他人)来说,这是可行的(受该线程中的上一篇文章的启发):

printf "Installed with pip:";
pip list 2>/dev/null | gawk '{print $1;}' | while read; do pip show "${REPLY}" 2>/dev/null | grep 'Location: /usr/local/lib/python2.7/dist-packages' >/dev/null; if (( $? == 0 )); then printf " ${REPLY}"; fi; done; echo

At least for Ubuntu (maybe also others) works this (inspired by a previous post in this thread):

printf "Installed with pip:";
pip list 2>/dev/null | gawk '{print $1;}' | while read; do pip show "${REPLY}" 2>/dev/null | grep 'Location: /usr/local/lib/python2.7/dist-packages' >/dev/null; if (( $? == 0 )); then printf " ${REPLY}"; fi; done; echo