如何在macOS X上正确地重新安装pip以使用venv? (EnviromentError:[Errno 13]权限被拒绝)

问题描述 投票:0回答:1

我是Python的新手,所以为了做一些练习,并决定创建一个venv,当我发现那些存在,并在那里做所有。

我在macOS X上,所以我已经拥有了Python2,但显然已经获得了3。

我从python.org本身安装了最新的Python版本。试图得到pip和venv但不会工作。所以,然后我安装了Homebrew并运行代码来安装python3,因为我读过它会带来pip等等。

它没有pip,它被证明非常难以安装它。因为我之前从未用Python编写过,所以创建一个venv让我迷失了。

我已经完成了我在终端所做的一切

我从https://www.python.org/downloads/为Mac OS X安装了最新的Python3.7.3我运行了包,它应该随附一切,但是当我跑的时候

MacBook-Air:~ maria$ pip --version
-bash: pip: command not found

所以我做了他们安装pip的指南说的

MacBook-Air:~ maria$ python -m ensurepip --default-pip

Ignoring indexes: https://pypi.python.org/simple
Requirement already satisfied (use --upgrade to upgrade): setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Collecting pip
Installing collected packages: pip
  Exception:
  Traceback (most recent call last):
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 246, in main
      status = self.run(options, args)
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/commands/install.py", line 352, in run
      root=options.root_path,
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 693, in install
      **kwargs
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/req/req_install.py", line 817, in install
      self.move_wheel_files(self.source_dir, root=root)
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/req/req_install.py", line 1018, in move_wheel_files
      isolated=self.isolated,
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/wheel.py", line 237, in move_wheel_files
      clobber(source, lib_dir, True)
    File "/var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpefPJJh/pip-6.1.1-py2.py3-none-any.whl/pip/wheel.py", line 208, in clobber
      os.makedirs(destdir)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
      mkdir(name, mode)
  OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'

然后我做了

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

结果

Installing collected packages: pip, wheel
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'
Consider using the `--user` option or check the permissions.

然后我甚至安装了Xcode的命令行开发人员工具,让它准备就绪并确保我没有遗漏任何东西。在此之后,我安装了Homebrew并用它来安装python3,我注意到它说

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite python

To list all files that would be deleted:
  brew link --overwrite --dry-run python

Possible conflicting files are:
/usr/local/bin/2to3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/2to3
/usr/local/bin/2to3-3.7 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/2to3-3.7
/usr/local/bin/idle3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/idle3
/usr/local/bin/idle3.7 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/idle3.7
/usr/local/bin/pydoc3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/pydoc3
/usr/local/bin/pydoc3.7 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/pydoc3.7
/usr/local/bin/python3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3-config -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config
/usr/local/bin/python3.7 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
/usr/local/bin/python3.7-config -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
/usr/local/bin/python3.7m -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
/usr/local/bin/python3.7m-config -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config
/usr/local/bin/pyvenv -> /Library/Frameworks/Python.framework/Versions/3.7/bin/pyvenv
/usr/local/bin/pyvenv-3.7 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/pyvenv-3.7
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> Caveats
Python has been installed as
  /usr/local/bin/python3

所以在它之后,我仍然跑了

MacBook-Air:~ maria$ pip --version
-bash: pip: command not found
MacBook-Air:~ maria$ python -m ensurepip --default-pip

结果

 OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'

加上最后一次

MacBook-Air:~ maria$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

但又得到了

Installing collected packages: pip, wheel
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'
Consider using the `--user` option or check the permissions.

所以,最后做了弃用的sudo easy_install pip

MacBook-Air:~ maria$ pip --version
pip 19.0.3 from /Library/Python/2.7/site-packages/pip-19.0.3-py2.7.egg/pip (python 2.7)
MacBook-Air:~ maria$ python3 -m ensurepip --default-pip
Looking in links: /var/folders/gj/g8j11snx2ll5xswmw_3696080000gn/T/tmpilb3zgrc
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (40.8.0)
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (19.0.3)

反对所有我担心弄乱的东西,但这很有效,具有讽刺意味。问题是我不能做venvs,因为我得到了[Errno 13] Permission denied,我不确定我是否想继续进行实验并把它弄得真实。

最后做了pip install --user pipenv,据说已经成功地用了一些笔记。

Installing collected packages: virtualenv-clone, enum34, typing, certifi, virtualenv, setuptools, pipenv
  The script virtualenv-clone is installed in '/Users/maria/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The script virtualenv is installed in '/Users/maria/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The scripts pipenv and pipenv-resolver are installed in '/Users/maria/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2019.3.9 enum34-1.1.6 pipenv-2018.11.26 setuptools-41.0.0 typing-3.6.6 virtualenv-16.4.3 virtualenv-clone-0.5.3

而且我不确定如何从这里开始。如果我正确地安装了所有东西,如果我现在就可以开始,或者我需要撤消某些东西,等等。在唠叨任何人之前我尽可能地尝试了。我愿意卸载所有内容并从0再次执行。

python macos pip homebrew sudo
1个回答
0
投票

从虚拟环境的文档: https://docs.python.org/3/tutorial/venv.html 要创建虚拟环境,请确定要放置它的目录,然后将venv模块作为脚本运行,并使用目录路径:python3 -m venv tutorial-env 然后激活虚拟环境:source tutorial-env/bin/activate 激活虚拟环境将改变shell的提示,以显示您正在使用的虚拟环境,并修改环境,以便运行python将获得特定版本和Python的安装。

© www.soinside.com 2019 - 2024. All rights reserved.