简体   繁体   中英

How to add a path like “C:\Users\Myname\Anaconda3\envs\pytorch\lib\site-packages” to sys.path permanently?

I am studying Pytorch, and I use Windows and Jupyter notebook.

When I try to import some modules like gym or cv2 on Pytorch Kernel, there are errors like 'no modules names gym'.

When I run sys.path on Pytorch there is no path "C:\\Users\\Myname\\Anaconda3\\envs\\pytorch\\lib\\site-packages\\IPython\\extensions", which is there on Python3 kernel.

So I used sys.path.append to add this path and I could import the modules successfully.

But is there a way to add this path permanently to my sys.path on Pytorch? Or should I type sys.path.append every time I run the different code?

C:\\Users\\Myname\\Anaconda3\\envs\\pytorch\\lib\\site-packages\\IPython\\extensions is a path from a virtualenv pytorch . You need to activate it in the Anaconda prompt before running a kernel :

C:\> C:\Users\Myname\Anaconda3\envs\pytorch\Scripts\activate

(pytorch) C:\> 

If you need to run something (semi-)automatically in this environment, see How to make batch files run in anaconda prompt .

If you need jupyter in this environment, you'll need to install corresponding conda packages into it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM