安装pipenv导致pip3无法使用

2024-04-27

我安装了pipenv using
$ pip3 install pipenv
这给了我错误ImportError: cannot import name 'main'
为了解决这个错误我遵循这些说明 https://stackoverflow.com/questions/49836676/python-pip3-cannot-import-name-main-error-after-upgrading-pip
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
now pip3命令正在终端上运行。
现在我安装pipenv using pip3 install pipenv
它安装成功,但是当我尝试执行时pipenv在终端上它给了我pipenv: command not found
在此刻pip3还给出ImportError: cannot import name 'main' error
为了解决这个问题我遵循这些说明 https://stackoverflow.com/questions/46391721/pipenv-command-not-found

PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"

在此刻pipenv正在工作但是pip3不管用 。
我怎样才能同时做到pip3 and pipenv同时工作?

另外,我似乎搞乱了我的 pipelinev 设置,现在虚拟环境是默认创建的/home/sysadmin而不是我用来创建虚拟环境的位置/home/sysadmin/Desktop/helloworld


该问题是由于安装pipenv时覆盖了系统管理的pip版本造成的。您执行了正确的第一步,使系统管理的点恢复正常:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

完成此操作后,需要注意的是,由于 pip 冲突,pipenv 可能无法在全局级别安装。您可以在用户级别安装 pipelinev:

pip install --user pipenv

这应该在 /home/username/.local 中的用户级别安装 pipelinev,这样它就不会与 pip 的全局版本冲突。就我而言,运行“--user”开关后仍然不起作用,因此我再次运行更长的“修复我搞砸的”命令来准备环境:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

然后执行以下操作:

mkdir /home/username/.local...如果它还不存在

export PYTHONUSERBASE=/home/username/.local

确保导出成功(在此过程中咬了我一次):

echo $PYTHONUSERBASE

然后,我运行了pip install --user pipenv一切都很好。然后我可以从 CLI 运行 pipelinev,它不会覆盖全局/系统管理的 pip 模块。当然,这是特定于用户的,因此您需要确保在以您希望使用 Pipenv 的用户身份工作时以这种方式安装 Pipenv。

参考:

https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv https://pip.pypa.io/en/stable/user_guide/#user-installs https://pip.pypa.io/en/stable/user_guide/#user-installs

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

安装pipenv导致pip3无法使用 的相关文章

随机推荐