标签归档:pip

点子为何从版本10升级到版本18?

问题:点子为何从版本10升级到版本18?

运行pip install脚本时收到以下警告:

 You are using pip version 10.0.1, however version 18.0 is available

这很奇怪。pip项目是否刚刚从版本10升级到版本18?为什么?

while running a pip install script I get the following warning:

 You are using pip version 10.0.1, however version 18.0 is available

This is very strange. Did the pip project just upgrade from version 10 to version 18? Why?


回答 0

发行说明中的​​第一点:

  • 切换到基于日历的版本控制方案。

https://pip.pypa.io/en/stable/news/

有关日历版本控制的更多信息:https : //calver.org/

First point in the release notes:

  • Switch to a Calendar based versioning scheme.

https://pip.pypa.io/en/stable/news/

More about calendar versioning: https://calver.org/


Windows上的pip安装访问被拒绝

问题:Windows上的pip安装访问被拒绝

我试图运行pip install mitmproxy在Windows,但我不断收到拒绝访问,甚至cmdPowerShell使用Run as Administrator选项。

WindowsError: [Error 5] Access is denied: 'c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u\\cryptography-0.9.1\\.eggs\\cffi-1.1.2-py2.7-win-amd64.egg\\_cffi_backend.pyd'

我该如何工作?

I am trying to run pip install mitmproxy on Windows, but I keep getting access denied, even with cmd and PowerShell using the Run as Administrator option.

WindowsError: [Error 5] Access is denied: 'c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u\\cryptography-0.9.1\\.eggs\\cffi-1.1.2-py2.7-win-amd64.egg\\_cffi_backend.pyd'

How can I make this work?


回答 0

如果是Windows,请在cmd中尝试使用python可执行文件运行pip install

例如

python -m pip install mitmproxy

这应该工作,至少对其他软件包安装来说对我有用。

In case of windows, in cmd try to run pip install using python executable

e.g.

python -m pip install mitmproxy

this should work, at least it worked for me for other package installation.


回答 1

通过以下方式更改Python安装文件夹的安全权限:

  1. 打开一个Python shell
  2. 转到任务管理器
  3. 查找python进程
  4. 右键单击并打开位置
  5. 该文件夹将在资源管理器中打开,进入目录
  6. 右键单击该文件夹,然后选择属性
  7. 点击安全标签,然后点击“编辑”
  8. 添加所有人,并授予他们读取和写入的权限。
  9. 保存更改

如果您cmd以管理员身份打开;那么您可以执行以下操作:

如果您的中设置了Python PATH,则:

python -m pip install mitmproxy

Change your Python installation folder’s security permissions by:

  1. Open a Python shell
  2. Go to task manager
  3. Find the python process
  4. Right-click and open location
  5. The folder will open in explorer, go up a directory
  6. Right-click the folder and select properties
  7. Click the security tab and hit ‘edit’
  8. Add everyone and give them permission to Read and Write.
  9. Save your changes

If you open cmd as admin; then you can do the following:

If Python is set in your PATH, then:

python -m pip install mitmproxy

回答 2

我个人发现,以管理员cmd身份打开然后运行 似乎可以解决我的问题。 python -m pip install mitproxy

注意:-我通过以下方式安装了pythonchocolatey

Personally, I found that by opening cmd as admin then run python -m pip install mitproxy seems to fix my problem.

Note:- I installed python through chocolatey


回答 3

以前的答案中未涉及的另一件事,尽管以admin身份运行,但通常会在Windows上引起问题,并且使我无法安装某些软件包,如果有另一个程序使用了某些文件,则会得到相同的权限被拒绝错误。 (要么pip install)尝试访问。这是Windows真正愚蠢的“功能”,它会多次弹出,例如在尝试移动某些文件时。

此外,我不知道如何找出哪个程序锁定了特定文件,因此最简单的方法是在开始任何操作之前,特别是在运行例如Spyder或任何其他基于Python的软件之前,重新引导并进行安装。您也可以尝试关闭所有程序,但是要知道哪个程序实际保存一个文件可能很棘手。例如,对于一个目录,在该目录中打开一个Explorer窗口就足够了。

One additional thing that has not been covered in previous answers and that often cause issues on Windows and stopped me from installing some package despite running as admin is that you get the same permission denied error if there is another program that use some of the files you (or pip install) try to access. This is a really stupid “feature” of Windows that pops up many times, e.g. when trying to move some files.

In addition I have no clue how to figure out which program locks a particular file, so the easiest ting to do is to reboot and do the installation before starting anything, in particular before running e.g. Spyder or any other Python-based software. You can also try to close all programs, but it can be tricky to know which one actually holds a file. For a directory for example, it is enough that you have an Explorer window open at that directory.


回答 4

使用“以管理员身份运行”打开cmd并执行命令pip install mitmproxy。它将安装它。

Open cmd with “Run as administrator” and execute the command pip install mitmproxy. It will install it.


回答 5

因为,我是通过anaconda Prompt安装的。在我的情况下,它甚至都无法使用python -m pip install然后,我添加了这个

python -m pip install <package_name> --user

这个对我有用。

喜欢: python -m pip install "numpy-1.15.4+mkl-cp36-cp36m-win_amd64.whl" --user

请注意,双引号不是必需的,您可以提供要安装的软件包名称。

另一个您应该尝试以“以管理员身份运行”身份运行命令提示符,然后尝试pip安装。它应该工作。

As, i am installing through anaconda Prompt .In my case, it didn’t even work with python -m pip install Then, i add this

python -m pip install <package_name> --user

It works for me.

Like: python -m pip install mitmproxy --user

Another you should try that run the Command Prompt as Run as Administrator and then try pip install. It should work either.


回答 6

尝试授予完全控制python文件夹的权限。

找到python根目录->右键单击->属性->安全->编辑->授予用户完全控制权限->是并等待过程完成。

这个对我有用。

Try to give permission to full control the python folder.

Find the python root directory–>right button click–>properties–>security–>edit–>give users Full Control–>yes and wait the process finished.

It works for me.


回答 7

尝试c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u手动删除文件夹,然后重试pip命令。

Try to delete the folder c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u manually and then retry the pip command.


回答 8

打开命令提示符,因为Administrator仅在不使用Python可执行文件的情况下为我工作。右键单击命令提示符快捷方式,然后选择“以管理员身份运行”。然后运行以下命令。

pip install Django

Opening command prompt As Administrator just worked for me without using Python executable. Right click on command prompt shortcut and choose “Run as Administrator”. Then run the following command.

pip install Django

回答 9

在我的情况下,原因是打开了一个Jupyter笔记本,该笔记本正在导入相关的库。根本原因似乎是Windows错误,原因是该文件处于打开状态/正在使用中(另请参见@Robert的回答以及有关重新启动的建议)。

所以要验证的另一件事是没有其他python进程在运行。

对我来说,关闭笔记本服务器可以解决此问题。

The cause in my case was having a jupyter notebook open, which was importing the relevant library; the root cause seems to be windows error due to the file being open / in use (see also @Robert’s answer, and the recommendation to reboot).

So another thing to verify is that no other python processes are running.

For me, shutting down the notebook server solved the issue.


回答 10

  1. 以管理员身份打开命令提示符。

  2. 要安装任何Python软件包,请使用包括以下命令--user

pip install --ignore-installed --upgrade --user <packagename>

  1. Open Command Prompt as Administrator.

  2. To Install any Python Package use this command including --user.

pip install --ignore-installed --upgrade --user <packagename>


回答 11

当其他所有方法均失败时,请尝试退出您的IDE。我有很多情况都是PyCharm造成的。退出PyCharm之后,我终于能够从命令行安装我的软件包。另外,您也可以通过PyCharm本身在设置->项目:xxx->项目解释器->中进行安装+

When all else fails, try quitting your IDE. I had many cases in which PyCharm was causing this. As soon as I quit PyCharm, I was able to finally install my packages from the command line. Alternatively, you can also install through PyCharm itself in Settings -> Project: xxx -> Project Interpreter -> +.


回答 12

以管理员身份运行cmd.exe,然后键入:

python -m pip install

Run cmd.exe as an administrator then type:

python -m pip install

回答 13

我遇到了类似的问题。但是错误报告是关于

[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)

首先,我尝试了此https://python-forum.io/Thread-All-pip-install-attempts-are-met-with-SSL-error#pid_28035,但似乎无法解决我的问题,仍然重复同样的问题。

其次,如果您在商用计算机上工作,通常它可能存在一个Web内容过滤器(但是我可以直接通过浏览器访问 https://pypi.python.org)。并通过添加代理服务器来解决此问题。

对于Windows,请Internet properties通过IE或Chrome或其他方式打开,然后设置有效的代理地址和端口,这样就可以解决我的问题

或者只是添加该选项pip --proxy [proxy-address]:port install mitmproxy。但是在通过pypi安装时,您始终需要添加此选项。

以上两种解决方案是您需要的替代方案。

I met a similar problem.But the error report is about

[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)

First I tried this https://python-forum.io/Thread-All-pip-install-attempts-are-met-with-SSL-error#pid_28035 ,but seems it couldn’t solve my problems,and still repeat the same issue.

And Second if you are working on a business computer,generally it may exist a web content filter(but I can access https://pypi.python.org through browser directly).And solve this issue by adding a proxy server.

For windows,open the Internet properties through IE or Chrome or whatsoever ,then set valid proxy address and port,and this way solve my problems

Or just adding the option pip --proxy [proxy-address]:port install mitmproxy.But you always need to add this option while installing by pypi

The above two solution is alternative for you demand.


回答 14

就我而言,它甚至无法与 python -m pip install

我所做的是,以管理员身份通过cmd:

PsExec.exe -i -s -d cmd.exe

为了产生SYSTEM cmd,然后 pip install mitmproxy

;)

In my case, it didn’t even work with python -m pip install

What I have done is, from a cmd as administrator:

PsExec.exe -i -s -d cmd.exe

In order to spawn a SYSTEM cmd, then pip install mitmproxy

;)


回答 15

只需关闭所有打开的python文件。并尝试以管理员身份运行。会的。

例如

pip install numpy

Just close all the python files opened. And try to run as administrator. It will work.

e.g.

pip install numpy

点冻结与点列表

问题:点冻结与点列表

比较输出结果可发现差异:

user@user-VirtualBox:~$ pip list
feedparser (5.1.3)
pip (1.4.1)
setuptools (1.1.5)
wsgiref (0.1.2)
user@user-VirtualBox:~$ pip freeze
feedparser==5.1.3
wsgiref==0.1.2

Pip的文档状态

freeze                      Output installed packages in requirements format.
list                        List installed packages.

但是什么是“需求格式”?为什么pip list生成的清单比清单更全面pip freeze

A comparison of outputs reveals differences:

user@user-VirtualBox:~$ pip list
feedparser (5.1.3)
pip (1.4.1)
setuptools (1.1.5)
wsgiref (0.1.2)
user@user-VirtualBox:~$ pip freeze
feedparser==5.1.3
wsgiref==0.1.2

Pip’s documentation states

freeze                      Output installed packages in requirements format.
list                        List installed packages.

but what is “requirements format,” and why does pip list generate a more comprehensive list than pip freeze?


回答 0

使用时virtualenv,可以指定一个requirements.txt文件来安装所有依赖项。

典型用法:

$ pip install -r requirements.txt

软件包需要采用特定的格式pip才能理解,即

feedparser==5.1.3
wsgiref==0.1.2
django==1.4.2
...

那就是“要求格式”。

在这里,django==1.4.2意味着安装django版本1.4.2(即使最新版本是1.6.x)。如果您未指定==1.4.2,则会安装可用的最新版本。

您可以在“ Virtualenv和pip基础知识 ”以及官方的“ Requirements File Format ”文档中阅读更多内容。

When you are using a virtualenv, you can specify a requirements.txt file to install all the dependencies.

A typical usage:

$ pip install -r requirements.txt

The packages need to be in a specific format for pip to understand, which is

feedparser==5.1.3
wsgiref==0.1.2
django==1.4.2
...

That is the “requirements format”.

Here, django==1.4.2 implies install django version 1.4.2 (even though the latest is 1.6.x). If you do not specify ==1.4.2, the latest version available would be installed.

You can read more in “Virtualenv and pip Basics“, and the official “Requirements File Format” documentation.


回答 1

为了回答这个问题的第二部分,显示pip list但没有显示的两个软件包pip freezesetuptools(easy_install)和它们pip本身。

它看起来像pip freeze少了点列表软件包点子本身依赖。您可以使用该--all标志来显示那些软件包。

文档中

--all

不要在输出中跳过以下软件包:pip,setuptools,distribute,wheel

To answer the second part of this question, the two packages shown in pip list but not pip freeze are setuptools (which is easy_install) and pip itself.

It looks like pip freeze just doesn’t list packages that pip itself depends on. You may use the --all flag to show also those packages.

From the documentation:

--all

Do not skip these packages in the output: pip, setuptools, distribute, wheel


回答 2

主要区别在于可以将的输出pip freeze转储到requirements.txt文件中,并在以后用于重建“冻结”环境。

换句话说,您可以运行:pip freeze > frozen-requirements.txt在一台计算机上运行 ,然后再在另一台计算机上或干净的环境中运行: pip install -r frozen-requirements.txt 您将获得与安装原始环境时所安装的依赖项完全相同的相同环境生成了Frozen-requirements.txt。

The main difference is that the output of pip freeze can be dumped into a requirements.txt file and used later to re-construct the “frozen” environment.

In other words you can run: pip freeze > frozen-requirements.txt on one machine and then later on a different machine or on a clean environment you can do: pip install -r frozen-requirements.txt and you’ll get the an identical environment with the exact same dependencies installed as you had in the original environment where you generated the frozen-requirements.txt.


回答 3

查看pip文档,该文档将两者的功能描述为:

点列表

列出已安装的软件包,包括可编辑的软件包。

点冻结

以需求格式输出已安装的软件包。

因此有两个区别:

  1. 输出格式,freeze为我们提供了标准的需求格式,以后可以用来pip install -r安装需求。

  2. 输出内容,pip list包括pip freeze不包含的可编辑内容。

Look at the pip documentation, which describes the functionality of both as:

pip list

List installed packages, including editables.

pip freeze

Output installed packages in requirements format.

So there are two differences:

  1. Output format, freeze gives us the standard requirement format that may be used later with pip install -r to install requirements from.

  2. Output content, pip list include editables which pip freeze does not.


回答 4

pip list显示所有软件包。

pip freeze示出了包YOU经由安装pip(或pipenv如果使用该工具)在要求的格式命令。

在下面说明创建虚拟信封时已安装setuptoolspipwheelpipenv shell。这些软件包不是我使用pip以下软件安装的:

test1 % pipenv shell
Creating a virtualenv for this project
Pipfile: /Users/terrence/Development/Python/Projects/test1/Pipfile
Using /usr/local/Cellar/pipenv/2018.11.26_3/libexec/bin/python3.8 (3.8.1) to create virtualenv
 Creating virtual environment...
<SNIP>
Installing setuptools, pip, wheel...
done.
 Successfully created virtual environment! 
<SNIP>

现在回顾与比较,我已经只安装了相应的命令的输出冷LIBsampleproject(其中胡椒是一个依赖):

test1 % pip freeze       <== Packages I'VE installed w/ pip

-e git+https://github.com/gdamjan/hello-world-python-package.git@10<snip>71#egg=cool_lib
peppercorn==0.6
sampleproject==1.3.1


test1 % pip list         <== All packages, incl. ones I've NOT installed w/ pip

Package       Version Location                                                                    
------------- ------- --------------------------------------------------------------------------
cool-lib      0.1  /Users/terrence/.local/share/virtualenvs/test1-y2Zgz1D2/src/cool-lib           <== Installed w/ `pip` command
peppercorn    0.6       <== Dependency of "sampleproject"
pip           20.0.2  
sampleproject 1.3.1     <== Installed w/ `pip` command
setuptools    45.1.0  
wheel         0.34.2

pip list shows ALL installed packages.

pip freeze shows packages YOU installed via pip (or pipenv if using that tool) command in a requirements format.

Remark below that setuptools, pip, wheel are installed when pipenv shell creates my virtual envelope. These packages were NOT installed by me using pip:

test1 % pipenv shell
Creating a virtualenv for this project…
Pipfile: /Users/terrence/Development/Python/Projects/test1/Pipfile
Using /usr/local/Cellar/pipenv/2018.11.26_3/libexec/bin/python3.8 (3.8.1) to create virtualenv…
⠹ Creating virtual environment...
<SNIP>
Installing setuptools, pip, wheel...
done.
✔ Successfully created virtual environment! 
<SNIP>

Now review & compare the output of the respective commands where I’ve only installed cool-lib and sampleproject (of which peppercorn is a dependency):

test1 % pip freeze       <== Packages I'VE installed w/ pip

-e git+https://github.com/gdamjan/hello-world-python-package.git@10<snip>71#egg=cool_lib
peppercorn==0.6
sampleproject==1.3.1


test1 % pip list         <== All packages, incl. ones I've NOT installed w/ pip

Package       Version Location                                                                    
------------- ------- --------------------------------------------------------------------------
cool-lib      0.1  /Users/terrence/.local/share/virtualenvs/test1-y2Zgz1D2/src/cool-lib           <== Installed w/ `pip` command
peppercorn    0.6       <== Dependency of "sampleproject"
pip           20.0.2  
sampleproject 1.3.1     <== Installed w/ `pip` command
setuptools    45.1.0  
wheel         0.34.2

pip成功安装软件包,但在命令行中找不到可执行文件

问题:pip成功安装软件包,但在命令行中找不到可执行文件

我正在使用Mac OS X Yosemite版本10.10.3。

我在http://johnlaudun.org/20150512-installing-and-setting-pip-with-macports/中使用macport安装了python2.7和pip

我可以成功安装软件包并将其导入我的python环境和python脚本中。但是,找不到与可以从终端中的命令行调用的软件包相关联的可执行文件。

有谁知道可能出什么问题了?(下面有更多详细信息)

例如,按照http://wiki.ros.org/jade/Installation/Source中的指示安装名为“ rosdep”的软件包时

我可以运行:sudo pip install -U rosdep 安装没有错误,并且相应文件位于/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

但是,如果我尝试运行:sudo rosdep init,则会出现错误:"sudo: rosdep: command not found"

这不是程序包特定的错误。对于在计算机上使用pip安装的所有软件包,我都会得到它。我什至尝试添加

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

对我的$PATH。但是,即使这些程序包可以在python内正常运行,也无法在命令行上找到可执行文件。

I am working on mac OS X Yosemite, version 10.10.3.

I installed python2.7 and pip using macport as done in http://johnlaudun.org/20150512-installing-and-setting-pip-with-macports/

I can successfully install packages and import them inside my python environment and python scripts. However any executable associated with a package that can be called from the command line in the terminal are not found.

Does anyone know what might be wrong? (More details below)

For example while installing a package called “rosdep” as instructed in http://wiki.ros.org/jade/Installation/Source

I can run: sudo pip install -U rosdep which installs without errors and corresponding files are located in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

However if I try to run : sudo rosdep init, it gives an error : "sudo: rosdep: command not found"

This is not a package specific error. I get this for any package installed using pip on my computer. I even tried adding

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

to my $PATH. But the executables are not found on the command line, even though the packages work perfectly from within python.


回答 0

检查您的$ PATH

tox 具有命令行模式:

audrey:tests jluc$ pip list | grep tox
tox (2.3.1)

它在哪里?

(编辑:这里的2.7东西没什么大不了的,无论是sub 3.x还是pip的行为都差不多)

audrey:tests jluc$ which tox
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/tox

我的$ PATH中有什么?

audrey:tests jluc$ echo $PATH
/opt/chefdk/bin:/opt/chefdk/embedded/bin:/opt/local/bin:..../opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin...

注意/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin吗?这就是找到我点子安装的东西的原因

现在,看到那里的东西都是从Python中,尝试这样做(替代rosdeptox)。

$python
>>> import tox
>>> tox.__file__

打印出来:

'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tox/__init__.pyc'

现在,将cd转到上面上方的目录lib。您看到bin目录吗?你看到rosdep那个垃圾箱了吗?如果是这样,请尝试将添加bin到您的$ PATH中。

audrey:2.7 jluc$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7
audrey:2.7 jluc$ ls -1

输出:

Headers
Python
Resources
bin
include
lib
man
share

check your $PATH

tox has a command line mode:

audrey:tests jluc$ pip list | grep tox
tox (2.3.1)

where is it?

(edit: the 2.7 stuff doesn’t matter much here, sub in any 3.x and pip’s behaving pretty much the same way)

audrey:tests jluc$ which tox
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/tox

and what’s in my $PATH?

audrey:tests jluc$ echo $PATH
/opt/chefdk/bin:/opt/chefdk/embedded/bin:/opt/local/bin:..../opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin...

Notice the /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin? That’s what allows finding my pip-installed stuff

Now, to see where things are from Python, try doing this (substitute rosdep for tox).

$python
>>> import tox
>>> tox.__file__

that prints out:

'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tox/__init__.pyc'

Now, cd to the directory right above lib in the above. Do you see a bin directory? Do you see rosdep in that bin? If so try adding the bin to your $PATH.

audrey:2.7 jluc$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7
audrey:2.7 jluc$ ls -1

output:

Headers
Python
Resources
bin
include
lib
man
share

回答 1

在具有默认python安装的macOS上,您需要添加/Users/<you>/Library/Python/2.7/bin/到$ PATH中。

将此添加到您的.bash_profile:

export PATH="/Users/<you>/Library/Python/2.7/bin:$PATH"

这就是pip安装可执行文件的地方。

提示:对于非默认的python版本which python,请找到您的python安装位置,并在上面的路径中替换该部分。(感谢提示Sanket_Diwale)

On macOS with the default python installation you need to add /Users/<you>/Library/Python/2.7/bin/ to your $PATH.

Add this to your .bash_profile:

export PATH="/Users/<you>/Library/Python/2.7/bin:$PATH"

That’s where pip installs the executables.

Tip: For non-default python version which python to find the location of your python installation and replace that portion in the path above. (Thanks for the hint Sanket_Diwale)


回答 2

如果您使用--user(例如pip3.6 install --user tmuxp)进行安装,则可以使用sitemodule 从Python本身获取特定于平台的用户安装目录。例如,在macOS上:

$ python2.7 -m site --user-base
/Users/alexp/Library/Python/2.7

通过附加/bin此内容,我们现在有了安装包可执行文件的路径。我们可以根据输出动态在您的Shell的rc文件中填充PATH;我正在使用bash,但是幸运的是,它是可移植的:

# Add Python bin directories to path
python3.6 -m site &> /dev/null && PATH="$PATH:`python3.6 -m site --user-base`/bin"
python2.7 -m site &> /dev/null && PATH="$PATH:`python2.7 -m site --user-base`/bin"

我使用精确的Python版本来减少当Python将次版本(例如从3.5升级到3.6)升级时可执行文件“消失”的机会。它们将消失,因为如上所示,用户安装路径可能包括Python版本。因此,虽然python3可能指向3.5或3.6,但python3.6始终将指向3.6。在安装其他软件包时,例如pip3.6在over上使用时,请记住这一点pip3

如果您不介意软件包消失的想法,可以使用python2python3代替:

# Add Python bin directories to path
# Note: When Python is upgraded, packages may need to be re-installed
#       or Python versions managed.
python3 -m site &> /dev/null && PATH="$PATH:`python3 -m site --user-base`/bin"
python2 -m site &> /dev/null && PATH="$PATH:`python2 -m site --user-base`/bin"

If you’re installing using --user (e.g. pip3.6 install --user tmuxp), it is possible to get the platform-specific user install directory from Python itself using the site module. For example, on macOS:

$ python2.7 -m site --user-base
/Users/alexp/Library/Python/2.7

By appending /bin to this, we now have the path where package executables will be installed. We can dynamically populate the PATH in your shell’s rc file based on the output; I’m using bash, but with any luck this is portable:

# Add Python bin directories to path
python3.6 -m site &> /dev/null && PATH="$PATH:`python3.6 -m site --user-base`/bin"
python2.7 -m site &> /dev/null && PATH="$PATH:`python2.7 -m site --user-base`/bin"

I use the precise Python versions to reduce the chance of the executables just “disappearing” when Python upgrades a minor version, e.g. from 3.5 to 3.6. They’ll disappear because, as can be seen above, the user installation path may include the Python version. So while python3 could point to 3.5 or 3.6, python3.6 will always point to 3.6. This needs to be kept in mind when installing further packages, e.g. use pip3.6 over pip3.

If you don’t mind the idea of packages disappearing, you can use python2 and python3 instead:

# Add Python bin directories to path
# Note: When Python is upgraded, packages may need to be re-installed
#       or Python versions managed.
python3 -m site &> /dev/null && PATH="$PATH:`python3 -m site --user-base`/bin"
python2 -m site &> /dev/null && PATH="$PATH:`python2 -m site --user-base`/bin"

回答 3

我知道问题是关于macOS的,但是这是通过Google到达Linux的Linux用户的解决方案。

我已经通过pip 安装了pdfx软件包,因此遇到了这个问题中描述的问题。

但是,当我运行它时,什么都没有…

pip list | grep pdfx
pdfx (1.3.0)

然而:

which pdfx
pdfx not found

在Linux上的问题是 pip install ...将脚本放入其中~/.local/bin,而不是默认的Debian / Ubuntu上的脚本$PATH

以下是GitHub问题的详细信息: https //github.com/pypa/pip/issues/3813

要解决此问题,只需将添加~/.local/bin$PATH,例如,将以下行添加到.bashrc文件中:

export PATH="$HOME/.local/bin:$PATH"

在那之后,重新启动您的外壳,一切应该按预期进行。

I know the question asks about macOS, but here is a solution for Linux users who arrive here via Google.

I was having the issue described in this question, having installed the pdfx package via pip.

When I ran it however, nothing…

pip list | grep pdfx
pdfx (1.3.0)

Yet:

which pdfx
pdfx not found

The problem on Linux is that pip install ... drops scripts into ~/.local/bin and this is not on the default Debian/Ubuntu $PATH.

Here’s a GitHub issue going into more detail: https://github.com/pypa/pip/issues/3813

To fix, just add ~/.local/bin to your $PATH, for example by adding the following line to your .bashrc file:

export PATH="$HOME/.local/bin:$PATH"

After that, restart your shell and things should work as expected.


回答 4

基于其他的答案,对linuxmac您可以运行以下命令:

echo "export PATH=\"`python3 -m site --user-base`/bin:$PATH\"" >> ~/.bashrc
source ~/.bashrc

而不是python3你可以使用任何其他链接到Python版本:pythonpython2.7python3.6python3.9,等。

说明

为了知道用户软件包在当前操作系统(win,mac,linux)中的安装位置,我们运行:

python3 -m site --user-base

我们知道脚本会转到bin/安装软件包的文件夹。

因此,我们将路径连接起来:

echo `python3 -m site --user-base`/bin

然后我们将其导出到环境变量。

export PATH=\"`python3 -m site --user-base`/bin:$PATH\""

最后,为了避免重复执行export命令,我们将其添加到.bashrc文件中,然后运行source以运行新更改,从而为我们提供了开头提到的建议解决方案。

Solution

Based on other answers, for linux and mac you can run the following:

echo "export PATH=\"`python3 -m site --user-base`/bin:$PATH\"" >> ~/.bashrc
source ~/.bashrc

instead of python3 you can use any other link to python version: python, python2.7, python3.6, python3.9, etc.

Explanation

In order to know where the user packages are installed in the current OS (win, mac, linux), we run:

python3 -m site --user-base

We know that the scripts go to the bin/ folder where the packages are installed.

So we concatenate the paths:

echo `python3 -m site --user-base`/bin

Then we export that to an environment variable.

export PATH=\"`python3 -m site --user-base`/bin:$PATH\"

Finally, in order to avoid repeating the export command we add it to our .bashrc file and we run source to run the new changes, giving us the suggested solution mentioned at the beginning.


回答 5

在Windows上,您需要将路径添加%USERPROFILE%\AppData\Roaming\Python\Scripts到您的路径。

On Windows, you need to add the path %USERPROFILE%\AppData\Roaming\Python\Scripts to your path.


回答 6

我偶然发现了这个问题,因为我创建,成功构建并发布了一个PyPI软件包,但安装后无法执行。该$PATH变量被设置正确。

就我而言,问题是我没有entry_pointsetup.py文件中设置:

entry_points = {'console_scripts':

['YOUR_CONSOLE_COMMAND=MODULE_NAME.FILE_NAME:FUNCTION_NAME'],},

I stumbled upon this question because I created, successfully built and published a PyPI Package, but couldn’t execute it after installation. The $PATHvariable was correctly set.

In my case the problem was that I hadn’t set the entry_pointin the setup.py file:

entry_points = {'console_scripts':

['YOUR_CONSOLE_COMMAND=MODULE_NAME.FILE_NAME:FUNCTION_NAME'],},

回答 7

除了将python的bin目录添加到$PATH变量之外,我还必须更改该目录的所有者以使其正常运行。不知道为什么我还不是所有者。

chown -R ~/Library/Python/

In addition to adding python’s bin directory to $PATH variable, I also had to change the owner of that directory, to make it work. No idea why I wasn’t the owner already.

chown -R ~/Library/Python/

回答 8

当您使用MacOS安装程序(可从Python网站下载)安装Python或Python3时,它将export~/.profile脚本中添加er 。您只需要做source。重新启动所有终端也可以解决问题。

警告-我认为最好将pip3与Python3配合使用-以获取未来的收益。

如果您已经安装了Python3,则以下步骤可在macOS Mojave上为我工作:

  1. 首先使用sudo– 安装ansiblesudo -H pip3 install ansible

  2. 您创建到Python bin路径的符号链接

sudo ln -s /Library/Frameworks/Python.framework/Versions/Current/bin /Library/Frameworks/Python.framework/current_python_bin

并装订到 .profile

export PATH=$PATH:/Library/Frameworks/Python.framework/current_python_bin

  1. 运行source ~/.profile并重新启动所有终端外壳。

  2. 类型 ansible --version

When you install Python or Python3 using MacOS installer (downloaded from Python website) – it adds an exporter to your ~/.profile script. All you need to do is just source it. Restarting all the terminals should also do the trick.

WARNING – I believe it’s better to just use pip3 with Python3 – for future benefits.

If you already have Python3 installed, the following steps work for me on macOS Mojave:

  1. Install ansible first using sudosudo -H pip3 install ansible

  2. you create a symlink to the Python’s bin path

sudo ln -s /Library/Frameworks/Python.framework/Versions/Current/bin /Library/Frameworks/Python.framework/current_python_bin

and staple it to .profile

export PATH=$PATH:/Library/Frameworks/Python.framework/current_python_bin

  1. run source ~/.profile and restart all terminal shells.

  2. Type ansible --version


如何将sqlite3模块添加到Python?

问题:如何将sqlite3模块添加到Python?

有人可以告诉我如何在最新版本的Python上安装sqlite3模块吗?我正在使用Macbook,并在命令行上尝试了:

pip install sqlite

但是会弹出一个错误。

Can someone tell me how to install the sqlite3 module alongside the most recent version of Python? I am using a Macbook, and on the command line, I tried:

pip install sqlite

but an error pops up.


回答 0

您不需要安装sqlite3模块。它包含在标准库中(自Python 2.5起)。

You don’t need to install sqlite3 module. It is included in the standard library (since Python 2.5).


回答 1

我有python 2.7.3,这解决了我的问题:

pip install pysqlite

I have python 2.7.3 and this solved my problem:

pip install pysqlite

回答 2

对于Python版本3:

pip install pysqlite3 

For Python version 3:

pip install pysqlite3 

回答 3

通常包括在内。但是,正如@ n​​gn999所说,如果您的python是从源代码手动构建的,则必须添加它。

这是一个脚本示例,该脚本将在用户目录中使用sqlite3封装版本设置Python3封装版本(虚拟环境)

INSTALL_BASE_PATH="$HOME/local"
cd ~
mkdir build
cd build
[ -f Python-3.6.2.tgz ] || wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
tar -zxvf Python-3.6.2.tgz

[ -f sqlite-autoconf-3240000.tar.gz ] || wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
tar -zxvf sqlite-autoconf-3240000.tar.gz

cd sqlite-autoconf-3240000
./configure --prefix=${INSTALL_BASE_PATH}
make
make install

cd ../Python-3.6.2
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib configure
LDFLAGS="-L ${INSTALL_BASE_PATH}/lib"
CPPFLAGS="-I ${INSTALL_BASE_PATH}/include"
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib make
./configure --prefix=${INSTALL_BASE_PATH}
make
make install

cd ~
LINE_TO_ADD="export PATH=${INSTALL_BASE_PATH}/bin:\$PATH"
if grep -q -v "${LINE_TO_ADD}" $HOME/.bash_profile; then echo "${LINE_TO_ADD}" >> $HOME/.bash_profile; fi
source $HOME/.bash_profile

为什么这样 对于独立的开发环境,您可能需要一个模块化的python环境,您可以在不影响操作系统的情况下完全销毁和重建它。在这种情况下,解决方案就是也要模块化安装sqlite3。

Normally, it is included. However, as @ngn999 said, if your python has been built from source manually, you’ll have to add it.

Here is an example of a script that will setup an encapsulated version (virtual environment) of Python3 in your user directory with an encapsulated version of sqlite3.

INSTALL_BASE_PATH="$HOME/local"
cd ~
mkdir build
cd build
[ -f Python-3.6.2.tgz ] || wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
tar -zxvf Python-3.6.2.tgz

[ -f sqlite-autoconf-3240000.tar.gz ] || wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
tar -zxvf sqlite-autoconf-3240000.tar.gz

cd sqlite-autoconf-3240000
./configure --prefix=${INSTALL_BASE_PATH}
make
make install

cd ../Python-3.6.2
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib configure
LDFLAGS="-L ${INSTALL_BASE_PATH}/lib"
CPPFLAGS="-I ${INSTALL_BASE_PATH}/include"
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib make
./configure --prefix=${INSTALL_BASE_PATH}
make
make install

cd ~
LINE_TO_ADD="export PATH=${INSTALL_BASE_PATH}/bin:\$PATH"
if grep -q -v "${LINE_TO_ADD}" $HOME/.bash_profile; then echo "${LINE_TO_ADD}" >> $HOME/.bash_profile; fi
source $HOME/.bash_profile

Why do this? You might want a modular python environment that you can completely destroy and rebuild without affecting your operating system–for an independent development environment. In this case, the solution is to install sqlite3 modularly too.


Python PIP安装会引发TypeError:-=:’Retry’和’int’不受支持的操作数类型

问题:Python PIP安装会引发TypeError:-=:’Retry’和’int’不受支持的操作数类型

使用pip install了显然与Python2.7.11+我的Ubuntu 16.04系统中的任何模块抛出这个错误:

TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

点子有什么问题?如有必要,如何重新安装?

更新:下面是完整的追溯

sunny@sunny:~$ pip install requests
Collecting requests
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

Using pip install for any module apparently on my Ubuntu 16.04 system with python 2.7.11+ throws this error:

TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

What is wrong with pip? How could I reinstall it, if necessary?

Update: Full traceback is below

sunny@sunny:~$ pip install requests
Collecting requests
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

回答 0

Ubuntu附带了前寒武纪的PIP版本,如果您不想花费数小时来调试与pip相关的问题,则必须升级它。

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

如您所见,我提供了有关Python 2.x和3.x的信息

Ubuntu comes with a version of PIP from precambrian and that’s how you have to upgrade it if you do not want to spend hours and hours debugging pip related issues.

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

As you observed I included information for both Python 2.x and 3.x


回答 1

如果您使用代理,则必须先执行一些额外的配置步骤,然后再开始安装。您必须将环境变量http_proxy设置为代理地址。使用bash可以通过以下命令完成

export http_proxy="http://user:pass@my.site:port/" 

您还可以提供

--proxy=[user:pass@]url:port 

点的参数。该[user:pass@]部分是可选的。

If you are behind a proxy, you must do some extra configuration steps before starting the installation. You must set the environment variable http_proxy to the proxy address. Using bash this is accomplished with the command

export http_proxy="http://user:pass@my.site:port/" 

You can also provide the

--proxy=[user:pass@]url:port 

parameter to pip. The [user:pass@] portion is optional.


回答 2

更新setuptools对我来说效果很好。

sudo pip install --upgrade setuptools

Updating setuptools has worked out fine for me.

sudo pip install --upgrade setuptools

回答 3

首先,由于网络问题而存在此问题,并且卸载和重新安装所有内容都不会有太大帮助。可能您落后于代理,在这种情况下,您需要设置代理。

但就我而言,我面临的问题是因为我没有落后于代理人。通常,我在代理后面工作,但是在家工作时,我在“网络”设置中将代理设置为“无”。

但是即使删除代理设置后,我仍然遇到相同的错误。

所以,当我输入

env | grep proxy

我发现了这样的事情:

http_proxy=http://127.0.0.1:1234/

这就是即使我以为我删除了代理设置,我仍然遇到同样错误的原因。

要取消设置此代理,请输入

unset http_proxy

对于所有其他条目(例如https_proxy),请采用相同的方法。

First of all, this problem exists because of network issues, and uninstalling and re-installing everything won’t be of much help. Probably you are behind proxy, and in that case you need to set proxy.

But in my case, I was facing the problem because I wasn’t behind proxy. Generally, I work behind proxy, but when working from home, I set the proxy to None in Network settings.

But I was still getting the same errors even after removing the proxy settings.

So, when I did type

env | grep proxy

I found something like this :

http_proxy=http://127.0.0.1:1234/

And this was the reason I was still getting the very same error, even when I thought I had removed the proxy settings.

To unset this proxy, type

unset http_proxy

Follow the same approach for all the other entries, such as https_proxy.


回答 4

这里发生的是,在两个不同的位置(相同的代码,但名称不同)导入时,request / urllib3的供应商版本发生冲突。如果随后出现网络错误,它不会重试,但是会因上述错误而失败。请参阅此处,深入了解此错误。

有关使用系统点的解决方案,请参见上文

如果您在由谁构建的virtualenv中有此问题python -m venv/usr/share/python-wheels即使您单独安装了pip,它仍然会从复制车轮),“修复”的最简单方法似乎是:

  1. 创建virtualenv: /usr/bin/python3.6 -m venv ...
  2. 安装requests到环境中(这可能会引发上述错误):<venv>/bin/pip install requests
  3. 删除requestspip将使用的复制版本:rm <venv>/share/python-wheels/{requests,chardet,urllib3}-*.whl

现在,a <venv>/bin/pip使用requests已提供urllib3的已安装版本。

What happens here is that the the vendored versions of request/urllib3 clash when imported in two different places (same code, but different names). If you then have a network error, it doesn’t retry to get the wheel, but fails with the above error. See here for a deeper dive into this error.

For the solution with system pip, see above.

If you have this problem in a virtualenv built by python -m venv (which still copies the wheels from /usr/share/python-wheels, even if you have pip installed separately), the easiest way to “fix” it seems to be:

  1. create the virtualenv: /usr/bin/python3.6 -m venv ...
  2. install requests into the environment (this might raise the above error): <venv>/bin/pip install requests
  3. remove the copied versions of requests which would be used by pip: rm <venv>/share/python-wheels/{requests,chardet,urllib3}-*.whl

Now a <venv>/bin/pip uses the installed version of requests which has urllib3 vendored.


回答 5

端口443未打开,如果在AWS上,则允许自定义tcp端口443,否则打开出站连接的端口443 …

port 443 is not open, just allow custom tcp port 443 if on AWS else open the port 443 for the outbound connections …


回答 6

只是升级点对我有用:

pip install --upgrade pip

Just upgrade pip worked for me:

pip install --upgrade pip


回答 7

使用pitft.sh / adafruit-pitft.sh从Adafruit安装RaspberryPI TFT时,我遇到同样的问题。

我不满意编码样式的错误,该错误来自某个地方,可以以某种方式解释-如前面的答案所示。

备注:的类型错误异常retry.py显然是一个错误,所造成的类的实例的unappropriate assignement和计算回复INT与默认值10 -在代码的某个地方……应该是固定的通过添加就地运算符或修正错误的分配。

因此,尝试首先分析和修补错误本身。在我的案例中,实际的错误是pip调用的相同的-retry.py

安装脚本adafruit-pitft.sh / pitft.sh尝试应用urllib3,后者本身尝试通过pip安装嵌套的依赖项,因此出现相同的错误。

adafruit-pitft.sh#或pitft.sh

_stacktrace = sys.exc_info()[2])文件“ /usr/share/python-wheels/urllib3-1.13.1-py2.py3 none-any.whl / urllib3 / util / retry.py”,第228行,增量

总计-= 1

TypeError:-=:“重试”和“ int”的不受支持的操作数类型

对于当前发行版(基于debian-9.6.0 / stretch):

文件“ /usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py”,行315,增量

总计-= 1

TypeError:-=:“重试”和“ int”的不受支持的操作数类型

以下-脏* :)-修补程序启用探测错误跟踪:

# File: retry.py - in *def increment(self, ..* about line 315
# original: total = self.total

# patch: quick-and-dirty-fix
# START:
if isinstance(self.total, Retry):
    self.total = self.total.total

if type(self.total) is not int:
    self.total = 2 # default is 10
# END:

# continue with original:
total = self.total

if total is not None:
    total -= 1

connect = self.connect
read = self.read
redirect = self.redirect
cause = 'unknown'
status = None
redirect_location = None

if error and self._is_connection_error(error):
    # Connect retry?
    if connect is False:
        raise six.reraise(type(error), error, _stacktrace)
    elif connect is not None:
        connect -= 1

带有临时补丁的声音输出为(显示两次…?):

连接被’ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at /

连接被’ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at /

找不到满足evdev要求的版本(来自版本:)

找不到与evdev匹配的分布

警告:Pip无法安装软件!

因此,就我而言,实际上是由两件事引起的错误,这在其他环境中可能会有所不同:

  1. 缺少evdev =>尝试安装
  2. 无法连接包含evdev的repo / dist 进行下载。=>最终放弃

我的安装环境是从内部debian + raspbian镜像脱机的,因此不想设置代理…

所以我着手手动安装缺少的组件evdev

  1. 从PyPI下载evdev(或例如从github.com下载):

    https://pypi.org/project/evdev/

    https://files.pythonhosted.org/packages/7e/53/374b82dd2ccec240b7388c65075391147524255466651a14340615aabb5f/evdev-1.1.2.tar.gz

  2. root用户身份解压缩并手动安装-对于所有本地帐户,因此被检测为已安装:

    苏多苏-

    tar xf evdev-1.1.2.tar.gz

    光盘evdev-1.1.2

    python setup.py安装

  3. 再次调用安装脚本:

    adafruit-pitft.sh#或pitft.sh

    回答对话

    …而已。

如果您通过直接PyPI访问进行在线操作:

  1. 检查您的路由和防火墙以访问pypi.org

  2. 根据需要设置代理(http_proxy / https_proxy)

而且有效。

希望这在其他情况下也有帮助。

阿尔诺·坎·乌斯图恩斯

———————————————-

另请参阅:问题-35334:https://bugs.python.org/issue35334

———————————————-

现在另请参阅:问题-1486:https : //github.com/urllib3/urllib3/issues/1486

用于文件:https : //github.com/urllib3/urllib3/blob/master/src/urllib3/util/retry.py

I have the same problem when installing a RaspberryPI TFT from Adafruit with pitft.sh / adafruit-pitft.sh.

I am not happy about coding-styles with errors from somewhere to be interpreted somehow – as could be seen by the previous answers.

Remark: The type error exception of retry.py is obviously a bug, caused by an unappropriate assignement and calculation of an instance of the class Reply to an int with the default value of 10 – somewhere in the code… Should be fixed either by adding an inplace-operator, or fixing the erroneous assignment.

So tried to analyse and patch the error itself first. The actual error in my case case is the same – retry.py called by pip.

The installation script adafruit-pitft.sh / pitft.sh tries to apply urllib3 which itself tries to install nested dependencies by pip, so the same error.

adafruit-pitft.sh # or pitft.sh

_stacktrace=sys.exc_info()[2]) File “/usr/share/python-wheels/urllib3-1.13.1-py2.py3 none-any.whl/urllib3/util/retry.py”, line 228, in increment

total -= 1

TypeError: unsupported operand type(s) for -=: ‘Retry’ and ‘int’

For the current distribution(based on debian-9.6.0/stretch):

File “/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py”, line 315, in increment

total -= 1

TypeError: unsupported operand type(s) for -=: ‘Retry’ and ‘int’

The following – dirty *:) – patch enables a sounding error trace:

# File: retry.py - in *def increment(self, ..* about line 315
# original: total = self.total

# patch: quick-and-dirty-fix
# START:
if isinstance(self.total, Retry):
    self.total = self.total.total

if type(self.total) is not int:
    self.total = 2 # default is 10
# END:

# continue with original:
total = self.total

if total is not None:
    total -= 1

connect = self.connect
read = self.read
redirect = self.redirect
cause = 'unknown'
status = None
redirect_location = None

if error and self._is_connection_error(error):
    # Connect retry?
    if connect is False:
        raise six.reraise(type(error), error, _stacktrace)
    elif connect is not None:
        connect -= 1

The sounding output with the temporary patch is(displayed twice…?):

Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by ‘ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at/

Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by ‘ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at/

Could not find a version that satisfies the requirement evdev (from versions: )

No matching distribution found for evdev

WARNING : Pip failed to install software!

So in my case actually two things cause the error, this may vary in other environments:

  1. Missing evdev => try to install
  2. Failed to connect a repo/dist containing evdev in order to download. => finally give it up

My installation environment is offline from an internal debian+raspbian mirror, thus do not want to set the proxy…

So I proceeded by manual installation of the missing component evdev:

  1. download evdev from PyPI(or e.g. from github.com):

    https://pypi.org/project/evdev/

    https://files.pythonhosted.org/packages/7e/53/374b82dd2ccec240b7388c65075391147524255466651a14340615aabb5f/evdev-1.1.2.tar.gz

  2. Unpack and install manually as root user – for all local accounts, so detected as installed:

    sudo su –

    tar xf evdev-1.1.2.tar.gz

    cd evdev-1.1.2

    python setup.py install

  3. Call install script again:

    adafruit-pitft.sh # or pitft.sh

    …Answer dialogues…

    …that’s it.

If you proceed online by direct PyPI access:

  1. check your routing + firewall for access to pypi.org

  2. set a proxy if required (http_proxy/https_proxy)

And it works..

Hope this helps in other cases too.

Arno-Can Uestuensoez

———————————————-

See also: issue – 35334: https://bugs.python.org/issue35334

———————————————-

See now also: issue – 1486: https://github.com/urllib3/urllib3/issues/1486

for file: https://github.com/urllib3/urllib3/blob/master/src/urllib3/util/retry.py


回答 8

检查网络问题,绕过异常案例代码

就我而言,我使用的是自定义索引,该索引没有路由,因此会触发异常案例代码。异常情况错误仍然存​​在,并且仍然掩盖了实际问题,但是我能够通过测试与其他工具的连接性来解决此问题,例如nc -vzw1 myindex.example.org 443在网络启动时重试。

check for network issues, to bypass the exception case code

In my case, I was using a custom index, that index had no route and such would trigger the exception case code. The exception case bug still exists and still masks the real issue, however I was able to work around this by testing the connectivity with other tools such as nc -vzw1 myindex.example.org 443 and retrying when the network was up.


回答 9

尝试在ec2实例上安装awscli工具时遇到了类似的问题。我更改了安全组,以允许端口443入站和出站访问,这为我解决了这个问题。

I was facing similar issue while trying to install awscli tool on ec2 instance. I changed security group to allow port 443 inbound and outbound access and that solved the issue for me.


回答 10

尝试创建virtualenvwith命令时收到此错误virtualenv myVirtualEnv。我只是sudo在命令前添加了一个;它解决了一切。

I got this error when I was trying to create a virtualenv with command virtualenv myVirtualEnv. I just added a sudo before the command; it solved everything.


回答 11

解决方案:
1. sudo apt remove python-pip
2. pip3 install pip(或通过get-pip.py安装pip )

原因:
此错误发生在apt-get安装的pip 8.0.1上。并且仅在您的网络不稳定时才发生。

如果您安装了带有apt的pip,则它将以其他方式隐藏您安装的pip,因此您应该首先删除该apt。

我断开了网络连接,并测试了通过pip3或get-pip.py安装的3个版本的8.0.1、9.0.3、10.x,没有发生错误。因此,我认为只有apt版本的pip 8.0.1才有该错误,其他都可以。

Solution:
1. sudo apt remove python-pip
2. pip3 install pip (or install pip by get-pip.py)

Why:
This error occurred on pip 8.0.1 which installed by apt-get. And happened only when your network is unstable.

If you have a pip installed with apt, it hides the pip you installed by other ways, so you should remove the apt one first.

I disconnected the network and tested 8.0.1, 9.0.3, 10.x the 3 versions installed with pip3 or get-pip.py, no error occurred.   So, I think only the apt version of pip 8.0.1 has that bug, the others is ok.


回答 12

就我而言,我以sudo模式打开了Pycharm,并在pycharm终端中运行了pip install nltk,该错误显示了此错误。使用sudo pip install运行可解决该错误。

In my case, i had opened Pycharm in sudo mode, and was running pip install nltk in pycharm terminal which showed this error. running with sudo pip install solves the error.


回答 13

我也有这个问题。最初,已设置代理,并且可以正常工作。然后,我连接到不通过代理的网络。取消设置代理点后,即可再次使用。

unset http_proxy; unset http_prox;  unset HTTP_PROXY; unset HTTPS_PROXY

I also had this issue. Initially, a proxy was set and work fine. Then I connected to a network where it doesn’t go through a proxy. After unsetting proxy pip again get works.

unset http_proxy; unset http_prox;  unset HTTP_PROXY; unset HTTPS_PROXY

回答 14

奇怪的是,如果我从环境中删除代理并将其添加到命令行,那么它对我有用。例如要pip自我升级:

env http_proxy= https_proxy= pip install pip --upgrade --proxy 'http://proxy-url:80'

我的问题是在环境中使用代理。看来,点子只是在参数中尊重那个人。

Bizarrely if I remove the proxy from the environment and add it to the command line it works for me. For example to upgrade pip itself:

env http_proxy= https_proxy= pip install pip --upgrade --proxy 'http://proxy-url:80'

My issue was having the proxy in the environment. It seems that pip only honors the one in argument.


回答 15

这是我发现的此问题的有效解决方案。

sudo apt-get clean
cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update

This is the working solution to this problem I found.

sudo apt-get clean
cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update

回答 16

对我自己来说,原来wlan0掉了下来,这导致我无法连接。因此,确保wlan0启动,允许pip / pip3正常工作。

For myself, it turns out that wlan0 was down, which resulted in me being unable to connect out. So, ensuring that wlan0 was up, allowed pip / pip3 to work without issue.


回答 17

我尝试了上面回答的解决方案:

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

当我尝试

python get-pip.py 
python3 get-pip.py

我收到此消息

 Could not install packages due to an EnvironmentError:
[Errno 13] Permission denied: /usr/bin/pip3 Consider using the --user
 option or check the permissions.

我做了以下工作

python3 -m venv env
source ./env/bin/activate
Sudo apt-get update 
apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py
pip3 install pip
sudo easy_install pip
pip install --upgrade pip

I tried the solution answered above:

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

When I tried

python get-pip.py 
python3 get-pip.py

I got this message

 Could not install packages due to an EnvironmentError:
[Errno 13] Permission denied: /usr/bin/pip3 Consider using the --user
 option or check the permissions.

I did the following and it works

python3 -m venv env
source ./env/bin/activate
Sudo apt-get update 
apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py
pip3 install pip
sudo easy_install pip
pip install --upgrade pip

使用virtualenv进行pip安装Matplotlib错误

问题:使用virtualenv进行pip安装Matplotlib错误

我正在尝试在新的virtualenv中安装matplotlib。

当我做:

pip install matplotlib

要么

pip install http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz

我收到此错误:

building 'matplotlib._png' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -  DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/local/include -I/usr/include -I. -I/home/sam/django-projects/datazone/local/lib/python2.7/site-packages/numpy/core/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-x86_64-2.7/src/_png.o

src/_png.cpp:10:20: fatal error: png.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

有人知道发生了什么吗?

任何帮助,不胜感激。

I am trying to install matplotlib in a new virtualenv.

When I do:

pip install matplotlib

or

pip install http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz

I get this error:

building 'matplotlib._png' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -  DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/local/include -I/usr/include -I. -I/home/sam/django-projects/datazone/local/lib/python2.7/site-packages/numpy/core/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-x86_64-2.7/src/_png.o

src/_png.cpp:10:20: fatal error: png.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

Anyone have an idea what is going on?

Any help much appreciated.


回答 0

构建Matplotlib需要libpngfreetype以及)不是python库,因此pip无法处理(或freetype)安装它。

您需要按照libpng-develfreetype-devel(或与您的操作系统等效的其他方式)安装一些东西。

请参阅matplotlib 的构建要求/说明

Building Matplotlib requires libpng (and freetype, as well) which isn’t a python library, so pip doesn’t handle installing it (or freetype).

You’ll need to install something along the lines of libpng-devel and freetype-devel (or whatever the equivalent is for your OS).

See the building requirements/instructions for matplotlib.


回答 1

要生成png格式的图形,您需要安装以下依赖包

sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev

Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0/ 或使用以下命令

sudo apt-get install libpng12-0

To generate graph in png format you need to Install following dependent packages

sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev

Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0/ or using following command

sudo apt-get install libpng12-0

回答 2

由于我两次都在这个问题上苦苦挣扎(即使在全新安装kubuntu 15.04之后),而安装freetype也解决不了任何问题,因此我进行了进一步调查。

解决方案:
来自github问题:

仅当未安装pkg-config时,才会发生此错误;
现在,简单的操作
sudo apt-get install pkg-config
将支持包含路径。

安装完成后顺利进行。

As I have struggled with this issue twice (even after fresh kubuntu 15.04 install) and installing freetype did not solve anything, I investigated further.

The solution:
From github issue:

This bug only occurs if pkg-config is not installed;
a simple
sudo apt-get install pkg-config
will shore up the include paths for now.

After this installation proceeds smoothly.


回答 3

作为补充,在Amazon EC2上,我需要做的是:

sudo yum install freetype-devel
sudo yum install libpng-devel
sudo pip install matplotlib

As a supplementary, on Amazon EC2, what I need to do is:

sudo yum install freetype-devel
sudo yum install libpng-devel
sudo pip install matplotlib

回答 4

在OSX上,我可以通过以下方式安装matplotlib:

pip install matplotlib==1.4.0

只有在我跑完之后:

brew install freetype

On OSX I was able to get matplotlib to install via:

pip install matplotlib==1.4.0

only after I ran:

brew install freetype

回答 5

在Windows下,这对我有用:

python -m pip install -U pip setuptools
python -m pip install matplotlib

(来自https://matplotlib.org/users/installing.html

Under Windows this worked for me:

python -m pip install -U pip setuptools
python -m pip install matplotlib

(from https://matplotlib.org/users/installing.html)


回答 6

sudo apt-get install libpng-dev libjpeg8-dev libfreetype6-dev

在Ubuntu 14.04上为我工作

sudo apt-get install libpng-dev libjpeg8-dev libfreetype6-dev

worked for me on Ubuntu 14.04


回答 7

以上答案均不适用于Mint,因此我做到了:

sudo apt-get install build-essential g++

None of the above answers worked for me in Mint, so I did:

sudo apt-get install build-essential g++

回答 8

如果在MacOSx上尝试

xcode-select --install

这符合subprocess 32,失败的原因。

If on MacOSx try

xcode-select --install

This complies subprocess 32, the reason for the failure.


回答 9

要减少安装所需的软件包,您只需要

apt-get install -y \
    libfreetype6-dev \
    libxft-dev && \
    pip install matplotlib

您将在本地安装以下软件包

Collecting matplotlib
  Downloading matplotlib-2.2.0-cp35-cp35m-manylinux1_x86_64.whl (12.5MB)
Collecting pytz (from matplotlib)
  Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
Collecting python-dateutil>=2.1 (from matplotlib)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
Requirement already satisfied: six>=1.10 in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages (from matplotlib)
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading kiwisolver-1.0.1-cp35-cp35m-manylinux1_x86_64.whl (949kB)
Requirement already satisfied: numpy>=1.7.1 in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages (from matplotlib)
Requirement already satisfied: setuptools in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg (from kiwisolver>=1.0.1->matplotlib)
Installing collected packages: pytz, python-dateutil, pyparsing, cycler, kiwisolver, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.0 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2018.3

To reduce the required packages to install you just need

apt-get install -y \
    libfreetype6-dev \
    libxft-dev && \
    pip install matplotlib

and you will get the following packages locally installed

Collecting matplotlib
  Downloading matplotlib-2.2.0-cp35-cp35m-manylinux1_x86_64.whl (12.5MB)
Collecting pytz (from matplotlib)
  Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
Collecting python-dateutil>=2.1 (from matplotlib)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
Requirement already satisfied: six>=1.10 in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages (from matplotlib)
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading kiwisolver-1.0.1-cp35-cp35m-manylinux1_x86_64.whl (949kB)
Requirement already satisfied: numpy>=1.7.1 in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages (from matplotlib)
Requirement already satisfied: setuptools in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg (from kiwisolver>=1.0.1->matplotlib)
Installing collected packages: pytz, python-dateutil, pyparsing, cycler, kiwisolver, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.0 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2018.3

回答 10

另一个选择是安装anaconda,该软件包随附以下软件包:Matplotlib,numpy和pandas。

https://anaconda.org

Another option is to install anaconda, which comes with packages such as: Matplotlib, numpy and pandas.

https://anaconda.org


如何在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


由于环境错误而无法安装软件包:[Errno 13]

问题:由于环境错误而无法安装软件包:[Errno 13]

在我的MacOS Mojave终端中,我想使用pip安装python软件包。最后说:

You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

所以我想用给定的命令更新点子,但出现错误:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 
'/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO'
Consider using the `--user` option or check the permissions.

我真的不知道该怎么办。我也意识到它在错误消息中说Python 2.7,但是我已经并且只想使用python 3。

In my MacOS Mojave terminal I wanted to install a python package with pip. At the end it says:

You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

So I wanted to update pip with the given command but I got an error:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 
'/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO'
Consider using the `--user` option or check the permissions.

I don’t really understand what to do now. Also I realized it says Python 2.7 in the error message but I have and want to use only python 3.


回答 0

如果要使用python3 +安装软件包,则需要使用pip3 install package_name

要解决errno 13,您必须--user在末尾添加

pip3 install package_name --user

编辑:

对于python中的任何项目,强烈建议Virtual enviroment上工作,该工具可通过为它们创建隔离的python虚拟环境来帮助将不同项目所需的依赖项分开。

为了使用python3 +创建一个,您必须使用以下命令:

virtualenv enviroment_name -p python3

然后只需激活它就可以对其进行处理:

source enviroment_name/bin/activate

激活虚拟环境后,虚拟环境的名称将显示在终端的左侧。这将使您知道虚拟环境当前处于活动状态。现在,您只需使用即可在该虚拟环境中安装与项目相关的依赖项pip

pip install package_name

If you want to use python3+ to install the packages you need to use pip3 install package_name

And to solve the errno 13 you have to add --user at the end

pip3 install package_name --user

EDIT:

For any project in python it’s highly recommended to work on a Virtual enviroment, is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.

In order to create one with python3+ you have to use the following command:

virtualenv enviroment_name -p python3

And then you work on it just by activating it:

source enviroment_name/bin/activate

Once the virtual environment is activated, the name of your virtual environment will appear on left side of terminal. This will let you know that the virtual environment is currently active. Now you can install dependencies related to the project in this virtual environment by just using pip.

pip install package_name

回答 1

关于权限命令,请尝试在终端命令前使用sudo:

sudo pip install --upgrade pip

Sudo允许您使用超级用户的特权运行命令,并将为全局,系统范围的Python安装安装软件包。理想情况下,您应该为正在处理的项目创建一个虚拟环境。看看这个

关于python尝试将pip作为可执行文件运行,如下所示:

python3.6 -m pip install <package>

Regarding the permissions command, try using sudo in front of your terminal command:

sudo pip install --upgrade pip

Sudo is a program that allows you to run the command with the privileges of the superuser.

Regarding the python Try running pip as an executable like this:

python3.6 -m pip install <package>

回答 2

我犯了同样的错误,然后意识到我已经以root用户身份创建了虚拟环境。它已被写保护,因此请检查您的虚拟环境是否被写保护。制作新的venv,然后重试

I was making the same mistakes then I realized that I have created my virtual environment as root user. It was write protected, so please check whether your virtual environment is write protected. make a new venv and try again


回答 3

尝试安装软件包时(烧瓶类),我遇到了相同的错误。
我犯了以root身份安装anaconda的错误。我更改了已安装的anaconda文件夹的所有权,并且可以成功安装该软件包。

使用chown带选项的命令-R来递归地更改已安装的anaconda文件夹的所有权,如下所示:

chown -R owner:group /path/to/anaconda

在这里所有者是您的用户名,组是组名。

I got the same error when I was trying to install a package (flask-classful).
I made the mistake of installing anaconda as root. I changed the ownership of the installed anaconda folder and I could install the package successfully.

Use the command chown with option -R to recursively change ownership of the installed anaconda folder like so:

chown -R owner:group /path/to/anaconda

Here owner is your username and group is the group name.


回答 4

答案在错误消息中。过去,您或某个进程执行sudo pip,并且导致该目录下的某些目录/Library/Python/2.7/site-packages/...具有权限,导致当前用户无法访问该目录。

然后您做了一个pip install whatever依赖另一件事的。

因此,要对其进行修复,请访问/Library/Python/2.7/site-packages / …并找到具有root或not-your-user权限的目录,然后删除然后重新安装这些软件包,或者只是强制对用户拥有所有权应该接触的人。

The answer is in the error message. In the past you or a process did a sudo pip and that caused some of the directories under /Library/Python/2.7/site-packages/... to have permissions that make it unaccessable to your current user.

Then you did a pip install whatever which relies on the other thing.

So to fix it, visit the /Library/Python/2.7/site-packages/… and find the directory with the root or not-your-user permissions and either remove then reinstall those packages, or just force ownership to the user to whom ought to have access.


回答 5

使用进行安装时numpy,我遇到了同样的问题pip install numpy

然后我尝试

sudo -H pip3 install --upgrade pip

sudo -H pip3 install numpy

对我来说效果很好。

说明:-H带(HOME)选项sudo设置HOME环境变量设置为目标用户(root默认情况下)的主目录。默认情况下,sudo不会修改HOME。

I had the same problem while installing numpy with pip install numpy.

Then I tried

sudo -H pip3 install --upgrade pip

sudo -H pip3 install numpy

It worked well for me.

Explanation : The -H (HOME) option with sudo sets the HOME environment variable to the home directory of the target user (root by default). By default, sudo does not modify HOME.


回答 6

对于MacO和Unix

只需在命令中添加sudo即可,因为它将以超级用户身份运行。

sudo pip install --upgrade pip

建议您不要直接这样做-请参阅这篇文章

For MacOs & Unix

Just by adding sudo to command will work, as it would run it as a superuser.

sudo pip install --upgrade pip

It is advised that you should not directly do it though – please see this post


回答 7

这为我工作:

 python3 -m venv env
 source ./env/bin/activate
 python -m pip install package

(来自Github:https : //github.com/googlesamples/assistant-sdk-python/issues/236

This worked for me:

 python3 -m venv env
 source ./env/bin/activate
 python -m pip install package

(From Github: https://github.com/googlesamples/assistant-sdk-python/issues/236 )


回答 8

我已经尝试过此处发布的所有建议,但仍收到errno 13

我正在使用Windows,而我的python版本是3.7.3

经过5小时的尝试解决后,此步骤对我有用:

我尝试以管理员身份运行以打开命令提示符

I already tried all suggestion posted in here, yet I’m still getting the errno 13,

I’m using Windows and my python version is 3.7.3

After 5 hours of trying to solve it, this step worked for me:

I try to open the command prompt by run as administrator


回答 9

我也遇到了同样的问题,我尝试了许多不同的命令行,这对我有用:

尝试:

    conda install py-xgboost

那就是我得到的:

Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/simplonco/anaconda3

  added / updated specs:
    - py-xgboost


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _py-xgboost-mutex-2.0      |            cpu_0           9 KB
    ca-certificates-2019.1.23  |                0         126 KB
    certifi-2018.11.29         |           py37_0         146 KB
    conda-4.6.2                |           py37_0         1.7 MB
    libxgboost-0.80            |       he6710b0_0         3.7 MB
    mkl-2019.1                 |              144       204.6 MB
    mkl_fft-1.0.10             |   py37ha843d7b_0         169 KB
    mkl_random-1.0.2           |   py37hd81dba3_0         405 KB
    numpy-1.15.4               |   py37h7e9f1db_0          47 KB
    numpy-base-1.15.4          |   py37hde5b4d6_0         4.2 MB
    py-xgboost-0.80            |   py37he6710b0_0         1.7 MB
    scikit-learn-0.20.2        |   py37hd81dba3_0         5.7 MB
    scipy-1.2.0                |   py37h7c811a0_0        17.7 MB
    ------------------------------------------------------------
                                           Total:       240.0 MB

The following NEW packages will be INSTALLED:

  _py-xgboost-mutex  pkgs/main/linux-64::_py-xgboost-mutex-2.0-cpu_0
  libxgboost         pkgs/main/linux-64::libxgboost-0.80-he6710b0_0
  py-xgboost         pkgs/main/linux-64::py-xgboost-0.80-py37he6710b0_0

The following packages will be UPDATED:

  ca-certificates     anaconda::ca-certificates-2018.12.5-0 --> pkgs/main::ca-certificates-2019.1.23-0
  mkl                                            2019.0-118 --> 2019.1-144
  mkl_fft                              1.0.4-py37h4414c95_1 --> 1.0.10-py37ha843d7b_0
  mkl_random                           1.0.1-py37h4414c95_1 --> 1.0.2-py37hd81dba3_0
  numpy                               1.15.1-py37h1d66e8a_0 --> 1.15.4-py37h7e9f1db_0
  numpy-base                          1.15.1-py37h81de0dd_0 --> 1.15.4-py37hde5b4d6_0
  scikit-learn                        0.19.2-py37h4989274_0 --> 0.20.2-py37hd81dba3_0
  scipy                                1.1.0-py37hfa4b5c9_1 --> 1.2.0-py37h7c811a0_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                          anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1a-h7b6447c_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
libxgboost-0.80      | 3.7 MB    | ##################################### | 100% 
mkl_random-1.0.2     | 405 KB    | ##################################### | 100% 
certifi-2018.11.29   | 146 KB    | ##################################### | 100% 
ca-certificates-2019 | 126 KB    | ##################################### | 100% 
conda-4.6.2          | 1.7 MB    | ##################################### | 100% 
mkl-2019.1           | 204.6 MB  | ##################################### | 100% 
mkl_fft-1.0.10       | 169 KB    | ##################################### | 100% 
numpy-1.15.4         | 47 KB     | ##################################### | 100% 
scipy-1.2.0          | 17.7 MB   | ##################################### | 100% 
scikit-learn-0.20.2  | 5.7 MB    | ##################################### | 100% 
py-xgboost-0.80      | 1.7 MB    | ##################################### | 100% 
_py-xgboost-mutex-2. | 9 KB      | ##################################### | 100% 
numpy-base-1.15.4    | 4.2 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

I also had the same problem, I tried many different command lines, this one worked for me:

Try:

    conda install py-xgboost

That’s what I got:

Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/simplonco/anaconda3

  added / updated specs:
    - py-xgboost


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _py-xgboost-mutex-2.0      |            cpu_0           9 KB
    ca-certificates-2019.1.23  |                0         126 KB
    certifi-2018.11.29         |           py37_0         146 KB
    conda-4.6.2                |           py37_0         1.7 MB
    libxgboost-0.80            |       he6710b0_0         3.7 MB
    mkl-2019.1                 |              144       204.6 MB
    mkl_fft-1.0.10             |   py37ha843d7b_0         169 KB
    mkl_random-1.0.2           |   py37hd81dba3_0         405 KB
    numpy-1.15.4               |   py37h7e9f1db_0          47 KB
    numpy-base-1.15.4          |   py37hde5b4d6_0         4.2 MB
    py-xgboost-0.80            |   py37he6710b0_0         1.7 MB
    scikit-learn-0.20.2        |   py37hd81dba3_0         5.7 MB
    scipy-1.2.0                |   py37h7c811a0_0        17.7 MB
    ------------------------------------------------------------
                                           Total:       240.0 MB

The following NEW packages will be INSTALLED:

  _py-xgboost-mutex  pkgs/main/linux-64::_py-xgboost-mutex-2.0-cpu_0
  libxgboost         pkgs/main/linux-64::libxgboost-0.80-he6710b0_0
  py-xgboost         pkgs/main/linux-64::py-xgboost-0.80-py37he6710b0_0

The following packages will be UPDATED:

  ca-certificates     anaconda::ca-certificates-2018.12.5-0 --> pkgs/main::ca-certificates-2019.1.23-0
  mkl                                            2019.0-118 --> 2019.1-144
  mkl_fft                              1.0.4-py37h4414c95_1 --> 1.0.10-py37ha843d7b_0
  mkl_random                           1.0.1-py37h4414c95_1 --> 1.0.2-py37hd81dba3_0
  numpy                               1.15.1-py37h1d66e8a_0 --> 1.15.4-py37h7e9f1db_0
  numpy-base                          1.15.1-py37h81de0dd_0 --> 1.15.4-py37hde5b4d6_0
  scikit-learn                        0.19.2-py37h4989274_0 --> 0.20.2-py37hd81dba3_0
  scipy                                1.1.0-py37hfa4b5c9_1 --> 1.2.0-py37h7c811a0_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                          anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1a-h7b6447c_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
libxgboost-0.80      | 3.7 MB    | ##################################### | 100% 
mkl_random-1.0.2     | 405 KB    | ##################################### | 100% 
certifi-2018.11.29   | 146 KB    | ##################################### | 100% 
ca-certificates-2019 | 126 KB    | ##################################### | 100% 
conda-4.6.2          | 1.7 MB    | ##################################### | 100% 
mkl-2019.1           | 204.6 MB  | ##################################### | 100% 
mkl_fft-1.0.10       | 169 KB    | ##################################### | 100% 
numpy-1.15.4         | 47 KB     | ##################################### | 100% 
scipy-1.2.0          | 17.7 MB   | ##################################### | 100% 
scikit-learn-0.20.2  | 5.7 MB    | ##################################### | 100% 
py-xgboost-0.80      | 1.7 MB    | ##################################### | 100% 
_py-xgboost-mutex-2. | 9 KB      | ##################################### | 100% 
numpy-base-1.15.4    | 4.2 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

回答 10

MacOS上尝试以下命令行,以检查用户的权限。

$ sudo python -m pip install --user --upgrade pip

try this command line below for MacOS to check user’s permission.

$ sudo python -m pip install --user --upgrade pip

回答 11

我为Python 3安装了anaconda。我的mac也有Python2。

python --version

给我

的Python 3.7.3

python2.7 --version

给我

Python 2.7.10

我想在python2中安装pyspark软件包,因为它已经安装在python3中。

python2.7 -m pip install pyspark

给我一个错误

由于环境错误而无法安装软件包:[Errno 13]权限被拒绝:’/Library/Python/2.7/site-packages/pyspark’考虑使用该--user选项或检查权限。

下面的命令解决了它。谢谢上帝,我不必做任何配置更改。

python2.7 -m pip install pyspark --user

收集pyspark的要求已经满足:/Library/Python/2.7/site-packages中的py4j == 0.10.7(来自pyspark)(0.10.7)安装收集的软件包:pyspark成功安装pyspark-2.4.4您正在使用pip版本18.1。 ,但是版本19.3.1可用。您应该考虑通过“ pip install –upgrade pip”命令进行升级。

I have anaconda installed for Python 3. I also have Python2 in my mac.

python --version

gives me

Python 3.7.3

python2.7 --version

gives me

Python 2.7.10

I wanted to install pyspark package in python2, given that it was already installed in python3.

python2.7 -m pip install pyspark

gives me an error

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/pyspark’ Consider using the --user option or check the permissions.

The below command solved it. Thank god I didn’t have to do any config changes.

python2.7 -m pip install pyspark --user

Collecting pyspark Requirement already satisfied: py4j==0.10.7 in /Library/Python/2.7/site-packages (from pyspark) (0.10.7) Installing collected packages: pyspark Successfully installed pyspark-2.4.4 You are using pip version 18.1, however version 19.3.1 is available. You should consider upgrading via the ‘pip install –upgrade pip’ command.


回答 12

我在具有所有正确权限的linux上已安装NTFS分区上的venv中遇到了类似的麻烦。确保使用–ignore-installed运行了pip可以解决该问题,即:

python -m pip install --upgrade --ignore-installed

I had similar trouble in a venv on a mounted NTFS partition on linux with all the right permissions. Making sure pip ran with –ignore-installed solved it, i.e.:

python -m pip install --upgrade --ignore-installed


回答 13

在Mac上,没有3.7目录,或者目录3.7归拥有root。因此,我删除了该目录,由当前用户创建了一个新目录,并将其移至该目录。然后安装完成,没有错误。

sudo rm -rf /Library/Python/3.7
mkdir 3.7
sudo mv 3.7 /Library/Python
ll /Library/Python/
pip3 install numpy

On Mac, there is no 3.7 directory or the directory 3.7 is owned by root. So, I removed that directory, create a new directory by current user, and move it there. Then installation finishes without error.

sudo rm -rf /Library/Python/3.7
mkdir 3.7
sudo mv 3.7 /Library/Python
ll /Library/Python/
pip3 install numpy

回答 14

当我尝试安装opencv-python软件包时,也会发生这种情况:

我可以用命令行修复它

python3 -m pip install {name of package} --user

当我尝试安装上述软件包时,命令变为:

python3 -m pip install opencv-python --user

结果是:

This also happens to me when I try to install the opencv-python package:

I can fix it with command line

python3 -m pip install {name of package} --user

When I try to install the said package, the command becomes:

python3 -m pip install opencv-python --user

Resulting in this:


回答 15

只是 sudo pip install packagename

just sudo pip install packagename


‘python setup.py install’和’pip install’之间的区别

问题:’python setup.py install’和’pip install’之间的区别

我有一个要从tar文件安装到python virtualenv中的外部软件包。安装软件包的最佳方法是什么?

我发现了两种方法可以做到这一点:

  1. 提取tar文件,然后python setup.py install在提取的目录中运行。
  2. pip install packagename.tar.gz来自https://pip.pypa.io/en/stable/reference/pip_install/#examples中的示例7

这两种方式在做上是否有区别。

I have an external package I want to install into my python virtualenv from a tar file. What is the best way to install the package?

I’ve discovered 2 ways that can do it:

  1. Extract the tar file, then run python setup.py install inside of the extracted directory.
  2. pip install packagename.tar.gz from example # 7 in https://pip.pypa.io/en/stable/reference/pip_install/#examples

Is if there is any difference doing them in these 2 ways.


回答 0

从表面上看,都做同样的事情:无论是做python setup.py install还是pip install <PACKAGE-NAME>会安装Python包的你,有大惊小怪的最低金额。

但是,使用pip具有一些其他优点,使其更易于使用。

  • pip将自动为您下载软件包的所有依赖项。相反,如果使用setup.py,则通常必须手动搜索并下载依赖项,这很乏味并且会令人沮丧。
  • pip跟踪各种元数据,使您可以使用一个命令轻松卸载和更新软件包:pip uninstall <PACKAGE-NAME>pip install --upgrade <PACKAGE-NAME>。相反,如果您使用setup.py,则要想摆脱它,必须手动手动删除和维护该软件包,这可能容易出错。
  • 您不再需要手动下载文件。如果您使用setup.py,则必须访问图书馆的网站,弄清楚从哪里下载,提取文件,运行setup.py…相比之下,pip会自动搜索Python软件包索引(PyPi)来查看该软件包是否存在,以及会自动为您下载,解压缩并安装该软件包。除了少数exceptions,几乎所有真正有用的Python库都可以在PyPi上找到。
  • pip可让您轻松安装轮子,这是Python发行版的新标准。有关轮子的更多信息
  • pip提供了与using良好集成的其他好处virtualenv,该程序使您可以运行多个项目,这些项目需要计算机上具有冲突的库和Python版本。更多信息
  • pip默认情况下与Python 2.x系列的Python 2.7.9及Python 3.x系列的Python 3.4.0及更高版本捆绑在一起,从而更加易于使用。

因此,基本上,使用点子。它仅提供对的改进python setup.py install


如果您使用的是旧版本的Python,无法升级且未安装pip,则可以在以下链接中找到有关安装pip的更多信息:

pip本身并不需要教程。90%的时间,您真正需要的唯一命令是pip install <PACKAGE-NAME>。就是说,如果您想了解更多有关pip的功能的详细信息,请参阅:

通常也建议同时使用pip和virtualenv。如果您是Python的初学者,我个人认为最好只使用pip并在全球范围内安装软件包,但最终我还是认为在处理更严重的项目时,您应该过渡到使用virtualenv。

如果您想了解有关一起使用pip和virtualenv的更多信息,请参见:

On the surface, both do the same thing: doing either python setup.py install or pip install <PACKAGE-NAME> will install your python package for you, with a minimum amount of fuss.

However, using pip offers some additional advantages that make it much nicer to use.

  • pip will automatically download all dependencies for a package for you. In contrast, if you use setup.py, you often have to manually search out and download dependencies, which is tedious and can become frustrating.
  • pip keeps track of various metadata that lets you easily uninstall and update packages with a single command: pip uninstall <PACKAGE-NAME> and pip install --upgrade <PACKAGE-NAME>. In contrast, if you install a package using setup.py, you have to manually delete and maintain a package by hand if you want to get rid of it, which could be potentially error-prone.
  • You no longer have to manually download your files. If you use setup.py, you have to visit the library’s website, figure out where to download it, extract the file, run setup.py… In contrast, pip will automatically search the Python Package Index (PyPi) to see if the package exists there, and will automatically download, extract, and install the package for you. With a few exceptions, almost every single genuinely useful Python library can be found on PyPi.
  • pip will let you easily install wheels, which is the new standard of Python distribution. More info about wheels.
  • pip offers additional benefits that integrate well with using virtualenv, which is a program that lets you run multiple projects that require conflicting libraries and Python versions on your computer. More info.
  • pip is bundled by default with Python as of Python 2.7.9 on the Python 2.x series, and as of Python 3.4.0 on the Python 3.x series, making it even easier to use.

So basically, use pip. It only offers improvements over using python setup.py install.


If you’re using an older version of Python, can’t upgrade, and don’t have pip installed, you can find more information about installing pip at the following links:

pip, by itself, doesn’t really require a tutorial. 90% of the time, the only command you really need is pip install <PACKAGE-NAME>. That said, if you’re interested in learning more about the details of what exactly you can do with pip, see:

It is also commonly recommended that you use pip and virtualenv together. If you’re a beginner to Python, I personally think it’d be fine to start of with just using pip and install packages globally, but eventually I do think you should transition to using virtualenv as you tackle more serious projects.

If you’d like to learn more about using pip and virtualenv together, see:


回答 1

python setup.py install与make install类似:这是将文件编译和复制到目标目录的有限方式。这并不意味着它是在系统上真正安装软件的最佳方法。

pip是一个程序包管理器,可以安装,升级,列出和卸载程序包,例如熟悉的程序包管理器,包括:dpkg, apt, yum, urpmi, ports等。它可以在内运行python setup.py install,但具有特定的选项来控制最终安装的方式和位置。

总结:使用pip

python setup.py install is the analog of make install: it’s a limited way to compile and copy files to destination directories. This doesn’t mean that it’s the best way to really install software on your system.

pip is a package manager, which can install, upgrade, list and uninstall packages, like familiar package managers including: dpkg, apt, yum, urpmi, ports etc. Under the hood, it will run python setup.py install, but with specific options to control how and where things end up installed.

In summary: use pip.


回答 2

问题是关于安装包含python软件包而不是NOT 的本地tarball的首选方法关于将软件包上传到索引服务(如PyPi)的好处。

至少我知道一些软件发行商不会将其软件包上传到PyPi,而是要求开发人员从其网站下载软件包并进行安装。

python setup.py安装

这可以工作,但不建议这样做。无需解压缩tarball文件并进入其中以运行setup.py文件。

点安装../path/to/packagename.tar.gz

这是设计和首选的方式。简洁并与PyPi样式的包对齐。

有关更多信息,请pip install参见:https//pip.readthedocs.io/en/stable/reference/pip_install/

The question is about the preferred method to install a local tarball containing a python package, NOT about the advantage of uploading package to an indexing service like PyPi.

As lest I know some software distributor does not upload their package to PyPi, instead asking developers to download package from their website and install.

python setup.py install

This can work but not recommended. It’s not necessary to unwrap the tarball file and go into it to run setup.py file.

pip install ../path/to/packagename.tar.gz

This is the way designed and preferred. Concise and align with PyPi-style packages.

More information about pip install can be found here: https://pip.readthedocs.io/en/stable/reference/pip_install/