安装pipenv后出现“ModuleNotFoundError:没有名为'yaml'的模块”

2024-09-30 10:35:46 发布

您现在位置:Python中文网/ 问答频道 /正文

终端输出如下所示。我创建了一个名为PrintCheckList的新文件夹,然后创建了一个pipenv环境,在那里我安装了pyyaml。我执行了pipenv shell,然后执行了python。当我尝试import yaml时,它失败了。pipenv站点包的ls显示它就在那里。我已经多次使用pipenv,但都没有这个问题

~/Python $ mkdir PrintCheckList
~/Python $ cd PrintCheckList/
~/Python/PrintCheckList $ pipenv --python 3.8 install pyyaml
Creating a virtualenv for this project…
Pipfile: /home/me/Python/PrintCheckList/Pipfile
Using /usr/local/bin/python3.8 (3.8.5) to create virtualenv…
⠦ Creating virtual environment...created virtual environment CPython3.8.5.final.0-64 in 378ms
  creator CPython3Posix(dest=/home/me/.local/share/virtualenvs/PrintCheckList-bTBe9zUr, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/me/.local/share/virtualenv)
    added seed packages: pip==20.2.2, setuptools==49.6.0, wheel==0.35.1
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

✔ Successfully created virtual environment! 
Virtualenv location: /home/me/.local/share/virtualenvs/PrintCheckList-bTBe9zUr
Creating a Pipfile for this project…
Installing pyyaml…
Adding pyyaml to Pipfile's [packages]…
✔ Installation Succeeded 
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Building requirements...
Resolving dependencies...
✔ Success! 
Updated Pipfile.lock (dc1c24)!
Installing dependencies from Pipfile.lock (dc1c24)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

~/Python/PrintCheckList $ pipenv shell
Launching subshell in virtual environment…
~/Python/PrintCheckList $  . /home/me/.local/share/virtualenvs/PrintCheckList-bTBe9zUr/bin/activate
(PrintCheckList) ~/Python/PrintCheckList $ pipenv graph
PyYAML==5.3.1
(PrintCheckList) ~/Python/PrintCheckList $ python
Python 3.8.5 (default, Sep  2 2020, 15:36:56) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'yaml'
>>> ^D

(PrintCheckList) ~/Python/PrintCheckList $ ls ~/.local/share/virtualenvs/PrintCheckList-bTBe9zUr/lib/python3.8/site-packages/
_distutils_hack           pip-20.2.2.dist-info    setuptools                    _virtualenv.py           yaml
distutils-precedence.pth  pip-20.2.2.virtualenv   setuptools-49.6.0.dist-info   wheel
easy_install.py           pkg_resources           setuptools-49.6.0.virtualenv  wheel-0.35.1.dist-info
pip                       PyYAML-5.3.1.dist-info  _virtualenv.pth               wheel-0.35.1.virtualenv
(PrintCheckList) ~/Python/PrintCheckList $

Tags: pipyamlsharehomevirtualenvpackageslocalpipenv
1条回答
网友
1楼 · 发布于 2024-09-30 10:35:46

我在.bashrc中去掉了这些别名,从而解决了这个问题:

alias python='/usr/local/bin/python3.8'
alias pip='/usr/local/bin/pip3.8'

相关问题 更多 >

    热门问题