Solution: jupyter notebook cannot import packages installed by itself

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
insert image description here
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

insert image description here

Solution:

insert image description here
insert image description here
insert image description here
insert image description here

Add environment variables PYTHONPATHand site-packagespaths to install packages

insert image description here
insert image description here

insert image description here

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

insert image description here
At this point, the package can be imported normally.
insert image description here

Guess you like

Origin blog.csdn.net/m0_56192771/article/details/127413857