删除 python2.7 后 mkvirtualenv 不工作

Posted

技术标签:

【中文标题】删除 python2.7 后 mkvirtualenv 不工作【英文标题】:mkvirtualenv is not working after deleting python2.7 【发布时间】:2019-12-01 23:15:43 【问题描述】:

从笔记本电脑中删除 python2.7 后,我开始收到此错误。 我正在尝试使用virtualenvwrapper mkvirtualenv 使用/bin/easy_install 创建虚拟环境。 我试过这个命令

╭─ fsadykov ~
╰─() mkvirtualenv --python=`which python` example

还有这个

╭─ fsadykov ~
╰─()  mkvirtualenv  example                                                                                                                                              1 ↵
New python executable in /Users/fsadykov/virtualenvs/example/bin/python
Please make sure you remove any previous custom paths from your /Users/fsadykov/.pydistutils.cfg file.
Installing setuptools, pip, wheel...

  Complete output from command /Users/fsadykov/virt...s/example/bin/python - setuptools pip wheel:
  DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in links: /Library/Python/2.7/site-packages/virtualenv_support
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl
Collecting pip
  Using cached https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
Installing collected packages: setuptools, pip, wheel
Could not install packages due to an EnvironmentError: [Errno 1] Operation not permitted: '/bin/easy_install'

----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 10, in <module>
    sys.exit(main())
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 810, in main
    symlink=options.symlink,
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 1105, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 952, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 1042, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 903, in call_subprocess
    raise OSError("Command  failed with error code ".format(cmd_desc, proc.returncode))
OSError: Command /Users/fsadykov/virt...s/example/bin/python - setuptools pip wheel failed with error code 1

版本

Virtualenvwrapper 版本

╭─ fsadykov ~
╰─() mkvirtualenv --version                                                              
16.4.0

Python 版本

╭─ fsadykov ~
╰─() python --version
Python 3.7.4

如果可能的话,我想从我的 MacBookPro 中删除 python2.7 并用于所有 python3.7。但由于某种原因,我收到了这个错误。

注意:此文件不存在/bin/easy_install

Could not install packages due to an EnvironmentError: [Errno 1] Operation not permitted: '/bin/easy_install'

【问题讨论】:

我对 virtualenvwrapper 不熟悉,但从日志来看,Python 2.x 似乎仍在使用中。另外,您是否注意到日志记录中的警告:Please make sure you remove any previous custom paths from your /Users/fsadykov/.pydistutils.cfg file. 我不确定该文件的用途是什么,但它可能包含您的 Python 2.x 安装路径?权限错误很可能是因为您需要root访问权限(sudo)才能写入/bin 感谢您的 cmets。我试过sudo 仍然面临这个错误。 sudo pip install flask Collecting flask Downloading Requirement already satisfied: itsdangerous&gt;=0.24 in /usr/local/lib/python3.7/site-packages (from flask) (0.24) Installing collected packages: Jinja2, Werkzeug, flask ERROR: Could not install packages due to an EnvironmentError: [Errno 1] Operation not permitted: '/bin/flask' 【参考方案1】:

你好,我只能给你建议。您应该重新安装 Python 并重试,似乎缺少一些文件。然后将 python 和 pip 都更新到最新版本。

【讨论】:

以上是关于删除 python2.7 后 mkvirtualenv 不工作的主要内容,如果未能解决你的问题,请参考以下文章

如何删除/root/.local/lib/python2.7?

centos7.5误删python2.7之后,导致yum和Python命令无法使用

在python2.7中删除字符串中的unicode \u2026之类的字符[重复]

Centos7安装Python2.7

推送后获取firebase密钥(python2.7)

Centos7卸载Python2.7.5&安装Python3.9.0的方法