The PIP installation package was successful but the import failed

the problem I ran into was not installing the package in the virtual environment, taking the jieba package as an example

enter python in the virtual environment, and then you can import the package. We thought it was packaged, but it was actually installed in the basic environment.

When

USES conda list to view the packages in the current environment, there is no jieba package.

conda list

forgot the screenshot,,,,

so you need to install jieba using the PIP of the virtual environment.


after confirming wrapping in a virtual environment, switching to a python environment cannot be done by simply typing python commands. Instead, use virtual environment Python, just like the previous PIP.

for example, you now have two files, test.py and test.sh.

test.py

import torch
print(torch.__version__)

test.sh

python test.py

you can see that the PIP version printed in the virtual environment is different from the one printed in the bash script.

so while I installed jieba in the pytorch1.4 environment, the command I used directly was not python in pytorch1.4, but python in the base environment.

summary:

  1. whether the package to the environment
  2. used the python interpreter is not the package environment interpreter

there are a lot of ways to do it online, so this is a supplement to what’s possible.


Read More: