Problem Description:
When using jupyter notebook to run the code,
pytorch is clearly installed in the virtual environment (the name of the virtual environment is pytorch), but an error is reported when importing the package, and the corresponding installation package cannot be found. Input and run the following
code in jupyter notebook to see The python library directory in the virtual environment found that it does not contain the path of my virtual environment at all (my virtual environment path is: C:\others\my_software\anaconda\envs\pytorch\Lib\site-packages
).
import sys
sys.path
Solution:
Add environment variables PYTHONPATH
and site-packages
paths to install packages
Check the python library directory in the virtual environment again, and find that it contains the path of my virtual environment (my virtual environment path is: C:\others\my_software\anaconda\envs\pytorch\Lib\site-packages
).
import sys
sys.path
At this point, the package can be imported normally.