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

时间:2020-09-26 03:51:07

标签: python pipenv pyyaml

端子输出如下所示。我创建了一个名为PrintCheckList的新文件夹,然后在安装pyyaml的地方创建了pipenv环境。我先执行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 $

1 个答案:

答案 0 :(得分:0)

我通过消除.bashrc中的这些别名来解决了这个问题:

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