【问题标题】:error when creating a pipenv virtual environment with python 3.7使用 python 3.7 创建 pipenv 虚拟环境时出错
【发布时间】:2021-01-21 19:52:16
【问题描述】:

我的操作系统是 ubuntu 20.04,我的默认 python 是 3.8.2。我正在尝试使用 pipenv 和 python 3.7 创建一个虚拟环境。运行pipenv install --python 3.7时出现以下错误:

Creating a virtualenv for this project…
Using /usr/bin/python3.7m (3.7.0) to create virtualenv…
⠋RuntimeError: failed to query /usr/bin/python3.7m with code 1 err: 'Traceback (most recent call last):\n  File "/usr/lib/python3/dist-packages/virtualenv/discovery/py_info.py", line 16, in <module>\n    from distutils.command.install import SCHEME_KEYS\nModuleNotFoundError: No module named \'distutils.command\'\n'
Error while trying to remove the /home/yuhao/.local/share/virtualenvs/electrode-mimic-j_E-dTLW env: 
No such file or directory

Virtualenv location: 
Warning: Your Pipfile requires python_version 3.7, but you are using None (/bin/python).
  $ pipenv check will surely fail.
Creating a virtualenv for this project…
Using /usr/bin/python3 (3.8.2) to create virtualenv…
⠙created virtual environment CPython3.8.2.final.0-64 in 162ms
  creator CPython3Posix(dest=/home/yuhao/.local/share/virtualenvs/electrode-mimic-j_E-dTLW, clear=False, global=False)
  seeder FromAppData(download=False, progress=latest, msgpack=latest, pytoml=latest, packaging=latest, setuptools=latest, contextlib2=latest, retrying=latest, pip=latest, pep517=latest, idna=latest, CacheControl=latest, appdirs=latest, requests=latest, pkg_resources=latest, webencodings=latest, distlib=latest, certifi=latest, distro=latest, ipaddr=latest, wheel=latest, six=latest, pyparsing=latest, urllib3=latest, chardet=latest, colorama=latest, lockfile=latest, html5lib=latest, via=copy, app_data_dir=/home/yuhao/.local/share/virtualenv/seed-app-data/v1.0.1.debian)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Virtualenv location: /home/yuhao/.local/share/virtualenvs/electrode-mimic-j_E-dTLW
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
^C
Aborted!

为什么会这样?

【问题讨论】:

    标签: python python-3.x virtualenv pipenv


    【解决方案1】:

    我在使用 Python 3.9.1 时遇到了同样的错误,所以我安装了 distutils

    sudo apt-get install python3.9-distutils 
    

    它可以工作

    【讨论】:

    • 也为我工作
    【解决方案2】:

    您是否安装了 python3-distutils 软件包? 如果没有,你可以安装它:

     sudo apt-get install python3-distutils
    

    【讨论】:

    • 我确实安装了它。
    • 你用 pip 安装了 pipenv 吗?
    • 我用 pip 安装的
    • 您可以尝试从源代码安装 python。有时 ubuntu 附带的 python 版本有问题。请参阅此处了解如何:realpython.com/installing-python/…
    • 我手动安装了 3.7.6 版本,它成功了!谢谢
    【解决方案3】:

    对于 python 11:

    sudo apt-get install python3.11-distutils 
    

    【讨论】:

      【解决方案4】:

      你应该试试:

          pipenv lock --clear
      

      它对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-21
        • 2023-03-05
        • 1970-01-01
        • 1970-01-01
        • 2022-08-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多