标签归档:python-3.3

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

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

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

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

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

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

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

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


回答 0

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

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

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

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

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

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

# use pip to install
pip install pyserial

要么:

# Don't want it?
pip uninstall pyserial

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

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

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

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

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

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

# use pip to install
pip install pyserial

or:

# Don't want it?
pip uninstall pyserial

回答 1

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

我安装了自制软件

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

然后:

brew doctor

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

然后:

brew install python3

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

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

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

I installed homebrew

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

then:

brew doctor

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

then:

brew install python3

This gave me python3 and pip3 in my path.

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

回答 2

在Mac上安装Python3

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

使用pip3安装模块

1. pip3 install ipython
2. python3 -m IPython

:)

Install Python3 on mac

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

Use pip3 to install modules

1. pip3 install ipython
2. python3 -m IPython

:)


回答 3

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

pip3 install requests

pip install requests

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

pip3 install requests

not

pip install requests

回答 4

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

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

➜〜pip3-版本

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

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

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

➜ ~ pip3 –version

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


回答 5

这是我的简单解决方案:

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

python3 -m pip install --upgrade pip

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

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

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

Here is my simple solution:

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

python3 -m pip install --upgrade pip

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

This will save memory and declutter your system.

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


回答 6

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

sudo easy_install pip

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

pip install pyserial

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

sudo easy_install pip

so then with pip to install Pyserial you would do:

pip install pyserial

回答 7

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

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

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

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

回答 8

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

~$ sudo pip3 install --upgrade pip

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

~$ sudo pip3 install --upgrade pip

回答 9

在MacOS 10.12上

下载点数:pip asget-pip.py

下载python3:python3

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

On MacOS 10.12

download pip: pip as get-pip.py

download python3: python3

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

回答 10

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

  1. brew install python3
  2. pip3 --version

pip is installed automatically with python2 using brew:

  1. brew install python3
  2. pip3 --version

回答 11

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

sudo easy_install pip

在此处下载python 3: python3

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

python3 --version
pip3 --version

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

sudo easy_install pip

download python 3 here: python3

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

python3 --version
pip3 --version

回答 12

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

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

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

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

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

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


回答 13

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

brew doctor

之后

brew reinstall python3

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

brew doctor

After that

brew reinstall python3

Python 3.3中的哈希函数在会话之间返回不同的结果

问题:Python 3.3中的哈希函数在会话之间返回不同的结果

我已经在python 3.3中实现了BloomFilter,并且每次会话都得到不同的结果。深入研究这种奇怪的行为,使我进入了内部hash()函数-它在每个会话中为同一字符串返回不同的哈希值。

例:

>>> hash("235")
-310569535015251310

—–打开一个新的python控制台—–

>>> hash("235")
-1900164331622581997

为什么会这样呢?为什么这有用?

I’ve implemented a BloomFilter in python 3.3, and got different results every session. Drilling down this weird behavior got me to the internal hash() function – it returns different hash values for the same string every session.

Example:

>>> hash("235")
-310569535015251310

—– opening a new python console —–

>>> hash("235")
-1900164331622581997

Why is this happening? Why is this useful?


回答 0

Python使用随机散列种子,通过向您发送旨在冲突的密钥来防止攻击者对应用程序进行处理。请参阅原始漏洞披露。通过使用随机种子(在启动时设置一次)偏移哈希值,攻击者无法再预测哪些键会发生冲突。

您可以通过设置PYTHONHASHSEED环境变量来设置固定种子或禁用功能;默认值为,random但您可以将其设置为固定的正整数值,同时0完全禁用该功能。

Python 2.7和3.2版本默认情况下禁用此功能(使用-R开关或设置PYTHONHASHSEED=random启用该功能);默认在Python 3.3及更高版本中启用它。

如果您依赖于Python集合中键的顺序,那么就不用了。Python使用哈希表来实现这些类型,它们的顺序取决于插入和删除的历史记录以及随机哈希种子。请注意,在Python 3.5及更低版本中,这也适用于字典。

另请参见object.__hash__()特殊方法文档

注意:默认情况下,__hash__()str,bytes和datetime对象的值使用不可预测的随机值“加盐”。尽管它们在单个Python进程中保持不变,但在重复调用Python之间是不可预测的。

这旨在提供保护,防止由于精心选择的输入而导致的拒绝服务,这些输入利用了dict插入的最坏情况的性能O(n ^ 2)复杂性。有关详细信息,请参见http://www.ocert.org/advisories/ocert-2011-003.html

更改哈希值会影响字典,集合和其他映射的迭代顺序。Python从未保证过这种顺序(通常在32位和64位版本之间有所不同)。

另请参阅PYTHONHASHSEED

如果需要稳定的哈希实现,则可能需要查看hashlib模块;这实现了加密哈希函数。该pybloom项目采用这种做法

由于偏移量由前缀和后缀(分别为起始值和最终XORed值)组成,因此,不幸的是,您不能仅存储偏移量。从正面来看,这确实意味着攻击者也无法通过定时攻击轻松确定偏移量。

Python uses a random hash seed to prevent attackers from tar-pitting your application by sending you keys designed to collide. See the original vulnerability disclosure. By offsetting the hash with a random seed (set once at startup) attackers can no longer predict what keys will collide.

You can set a fixed seed or disable the feature by setting the PYTHONHASHSEED environment variable; the default is random but you can set it to a fixed positive integer value, with 0 disabling the feature altogether.

Python versions 2.7 and 3.2 have the feature disabled by default (use the -R switch or set PYTHONHASHSEED=random to enable it); it is enabled by default in Python 3.3 and up.

If you were relying on the order of keys in a Python set, then don’t. Python uses a hash table to implement these types and their order depends on the insertion and deletion history as well as the random hash seed. Note that in Python 3.5 and older, this applies to dictionaries, too.

Also see the object.__hash__() special method documentation:

Note: By default, the __hash__() values of str, bytes and datetime objects are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python.

This is intended to provide protection against a denial-of-service caused by carefully-chosen inputs that exploit the worst case performance of a dict insertion, O(n^2) complexity. See http://www.ocert.org/advisories/ocert-2011-003.html for details.

Changing hash values affects the iteration order of dicts, sets and other mappings. Python has never made guarantees about this ordering (and it typically varies between 32-bit and 64-bit builds).

See also PYTHONHASHSEED.

If you need a stable hash implementation, you probably want to look at the hashlib module; this implements cryptographic hash functions. The pybloom project uses this approach.

Since the offset consists of a prefix and a suffix (start value and final XORed value, respectively) you cannot just store the offset, unfortunately. On the plus side, this does mean that attackers cannot easily determine the offset with timing attacks either.


回答 1

默认情况下,Python 3中启用了哈希随机化。这是一个安全功能:

散列随机化旨在提供保护,防止由于精心选择的输入而导致的拒绝服务攻击,这些输入利用了dict构造的最坏情况性能

在2.6.8之前的版本中,可以使用-R或PYTHONHASHSEED环境选项在命令行中将其打开

您可以将其设置PYTHONHASHSEED为零以将其关闭。

Hash randomisation is turned on by default in Python 3. This is a security feature:

Hash randomization is intended to provide protection against a denial-of-service caused by carefully-chosen inputs that exploit the worst case performance of a dict construction

In previous versions from 2.6.8, you could switch it on at the command line with -R, or the PYTHONHASHSEED environment option.

You can switch it off by setting PYTHONHASHSEED to zero.


回答 2

hash()是Python的内置函数,可用于为对象而不是字符串或num 计算哈希值。

您可以在以下页面中查看详细信息:https : //docs.python.org/3.3/library/functions.html#hash

hash()值来自对象的__hash__方法。该文档说以下内容:

默认情况下,str,bytes和datetime对象的hash()值会以不可预测的随机值“成盐”。尽管它们在单个Python进程中保持不变,但在重复调用Python之间是不可预测的。

这就是为什么您在不同的控制台中对同一字符串具有不同的哈希值的原因。

您实施的方法不是一个好方法。

当您要计算字符串哈希值时,只需使用hashlib

hash()的目的是获取对象的哈希值,而不是搅动。

hash() is a Python built-in function and use it to calculate a hash value for object, not for string or num.

You can see the detail in this page: https://docs.python.org/3.3/library/functions.html#hash.

and hash() values comes from the object’s __hash__ method. The doc says the followings:

By default, the hash() values of str, bytes and datetime objects are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python.

That’s why your have diffent hash value for the same string in different console.

What you implement is not a good way.

When you want to calculate a string hash value, just use hashlib

hash() is aim to get a object hash value, not a stirng.


Python 3:ImportError“没有名为Setuptools的模块”

问题:Python 3:ImportError“没有名为Setuptools的模块”

我在使用Python 3安装软件包时遇到了麻烦。

我一直都使用来安装软件包setup.py install。但是现在,当我尝试安装ansicolors软件包时,我得到了:

importerror“没有名为Setuptools的模块”

我不知道该怎么办,因为过去我没有安装过setuptools。尽管如此,我仍然能够在setup.py install没有setuptools的情况下安装许多软件包。为什么现在应该获得setuptools?

我什至无法安装setuptools,因为我有Python 3.3,setuptools不支持Python 3。

为什么我的安装命令不再起作用?

I’m having troubles with installing packages in Python 3.

I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get:

importerror “No Module named Setuptools”

I have no idea what to do because I didn’t have setuptools installed in the past. Still, I was able to install many packages with setup.py install without setuptools. Why should I get setuptools now?

I can’t even install setuptools because I have Python 3.3 and setuptools doesn’t support Python 3.

Why doesn’t my install command work anymore?


回答 0

您的setup.py文件需要setuptools。一些Python软件包曾经distutils用于分发,但现在大多数都使用setuptools了一个更完整的软件包。是有关它们之间差异的问题。

setuptools在Debian上安装:

sudo apt-get install python3-setuptools

对于旧版本的Python(Python 2.x):

sudo apt-get install python-setuptools

Your setup.py file needs setuptools. Some Python packages used to use distutils for distribution, but most now use setuptools, a more complete package. Here is a question about the differences between them.

To install setuptools on Debian:

sudo apt-get install python3-setuptools

For an older version of Python (Python 2.x):

sudo apt-get install python-setuptools

回答 1

编辑:官方setuptools dox页面

如果您从python.org安装了Python 2> = 2.7.9或Python 3> = 3.4,则已经具有pip和setuptools,但需要升级到最新版本:

在Linux或OS X上:

pip install -U pip setuptools 

在Windows上:

python -m pip install -U pip setuptools

因此,本文的其余部分可能已过时(例如,某些链接不起作用)。

分发 -是setuptools分支,可“提供Python 3支持”。Distribution(setuptools)+ pip的安装说明:

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

这里有类似的问题。

更新:分发似乎已过时,即已合并到Setuptools中:分发是Setuptools项目不推荐使用的分支。从Setuptools 0.7发行版开始,Setuptools和Distribute已合并,并且不再维护Distribute。所有正在进行的工作应参考Setuptools项目和Setuptools文档。

您可以尝试在setuptools pypi页面上找到说明(我尚未对此进行测试,对不起:():

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip

EDIT: Official setuptools dox page:

If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:

On Linux or OS X:

pip install -U pip setuptools 

On Windows:

python -m pip install -U pip setuptools

Therefore the rest of this post is probably obsolete (e.g. some links don’t work).

Distribute – is a setuptools fork which “offers Python 3 support”. Installation instructions for distribute(setuptools) + pip:

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

Similar issue here.

UPDATE: Distribute seems to be obsolete, i.e. merged into Setuptools: Distribute is a deprecated fork of the Setuptools project. Since the Setuptools 0.7 release, Setuptools and Distribute have merged and Distribute is no longer being maintained. All ongoing effort should reference the Setuptools project and the Setuptools documentation.

You may try with instructions found on setuptools pypi page (I haven’t tested this, sorry :( ):

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip

回答 2

我在使用python-2.6的Oracle Linux 6.4上的virtualenv内执行此操作,因此基于apt的解决方案对我来说不是一个选择,python-2.7的想法也不对。我的解决方法是升级我由virtualenv安装的setuptools版本:

pip install --upgrade setuptools

之后,我能够将软件包安装到virtualenv中。我知道这个问题已经选择了答案,但我希望这个答案对我的情况有所帮助。

I was doing this inside a virtualenv on Oracle Linux 6.4 using python-2.6 so the apt-based solutions weren’t an option for me, nor were the python-2.7 ideas. My fix was to upgrade my version of setuptools that had been installed by virtualenv:

pip install --upgrade setuptools

After that, I was able to install packages into the virtualenv. I know this question has already had an answer selected but I hope this answer will help others in my situation.


回答 3

pip uninstall setuptools

然后:

pip install setuptools

这对我有用,并解决了我的问题。

pip uninstall setuptools

and then:

pip install setuptools

This works for me and fix my issue.


回答 4

distribute软件包提供了与Python 3兼容的版本setuptoolshttp : //pypi.python.org/pypi/distribute

另外,用于pip安装模块。它会自动找到依赖项并为您安装它们。

对于您的包裹,它对我来说效果很好:

[~] pip --version                                                              
pip 1.2.1 from /usr/lib/python3.3/site-packages (python 3.3)
[~] sudo pip install ansicolors                                                
Downloading/unpacking ansicolors
  Downloading ansicolors-1.0.2.tar.gz
  Running setup.py egg_info for package ansicolors

Installing collected packages: ansicolors
  Running setup.py install for ansicolors

Successfully installed ansicolors
Cleaning up...
[~]

The distribute package provides a Python 3-compatible version of setuptools: http://pypi.python.org/pypi/distribute

Also, use pip to install the modules. It automatically finds dependencies and installs them for you.

It works just fine for me with your package:

[~] pip --version                                                              
pip 1.2.1 from /usr/lib/python3.3/site-packages (python 3.3)
[~] sudo pip install ansicolors                                                
Downloading/unpacking ansicolors
  Downloading ansicolors-1.0.2.tar.gz
  Running setup.py egg_info for package ansicolors

Installing collected packages: ansicolors
  Running setup.py install for ansicolors

Successfully installed ansicolors
Cleaning up...
[~]

回答 5

Windows 7的:

我在这里为python selenium webdriver 提供了完整的解决方案

1. Setup easy install (windows - simplified)
    a. download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
    b. move ez.setup.py to C:\Python27\
    c. open cmd prompt
    d. cd C:\Python27\
    e. C:\Python27\python.exe ez.setup.py install

Windows 7:

I have given a complete solution here for python selenium webdriver

1. Setup easy install (windows - simplified)
    a. download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
    b. move ez.setup.py to C:\Python27\
    c. open cmd prompt
    d. cd C:\Python27\
    e. C:\Python27\python.exe ez.setup.py install

回答 6

PyPA推荐的用于安装和管理Python包的工具pippip包括在Python 3.4(PEP 453),但对于旧版本这里是如何安装它(在Windows上):

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

>c:\Python33\python.exe get-pip.py
Downloading/unpacking pip
Downloading/unpacking setuptools
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...

>c:\Python33\Scripts\pip.exe install pymysql
Downloading/unpacking pymysql
Installing collected packages: pymysql
Successfully installed pymysql
Cleaning up...

The PyPA recommended tool for installing and managing Python packages is pip. pip is included with Python 3.4 (PEP 453), but for older versions here’s how to install it (on Windows):

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

>c:\Python33\python.exe get-pip.py
Downloading/unpacking pip
Downloading/unpacking setuptools
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...

>c:\Python33\Scripts\pip.exe install pymysql
Downloading/unpacking pymysql
Installing collected packages: pymysql
Successfully installed pymysql
Cleaning up...

回答 7

几年前,我继承了在Django-1.2.3下运行的python(2.7.1)项目,现在被要求使用QR增强功能。遇到了同样的问题,没有找到pip或apt-get。所以我以完全不同但简单的方式解决了它。我/ bin / vi-ed setup.py,并将“ from setuptools import setup”这一行更改为:“ from distutils.core import setup”对我而言,所以我认为我应该将它发布给其他运行旧python的用户。问候,罗杰·维米尔

A few years ago I inherited a python (2.7.1) project running under Django-1.2.3 and now was asked to enhance it with QR possibilities. Got the same problem and did not find pip or apt-get either. So I solved it in a totally different but easy way. I /bin/vi-ed the setup.py and changed the line “from setuptools import setup” into: “from distutils.core import setup” That did it for me, so I thought I should post this for other users running old pythons. Regards, Roger Vermeir