Pycharm failing to import libary
I'm trying to play around with the Jupyter functionality in Pycharm, and to do this I created a new project from an existing notebook. I set the interpreter to an existing conda environment. When I try to run my import cell, it raises a "No module" error for a dependency that is contained in one of the main libraries I'm importing. The thing is, this all works just fine in VSC using the same file and same conda environment. I tried creating a pure python project with the same environment and importing the library and had the same issue.
I'm a little perplexed - it just shouldn't be complicated to open a file, point the interpreter at the executable in an existing environment, and go.
Please sign in to leave a comment.
Hi,
>this all works just fine in VSC
Could you try printing sys.path both from PyCharm and VS Code, and compare the paths? Are they different? What about paths to your dependencies?
So, the missing dependency was matplotlib, which I am pretty sure was automatically pulled into the environment by pip when I installed trax. I manually went back and added it, which solved the problem in Pycharm, but unfortunately that means I have no idea if it was actually there in the first place. I am now wondering if VSC was doing something that I don't understand, since the sys.path information below doesn't even show the virtual env that it should despite having it as the current interpreter (impossible that it's another env, since no other envs on this system have trax installed). Long story short, I have no idea what VSC is doing and this isn't the place for that anyway. In any case, the problem was resolved. I'll include the library search paths below in case they indicate anything awry.
_______
FROM PYCHARM:
'/home/tyarosevich/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7319.64/plugins/python/helpers/pydev',
'/home/tyarosevich/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7319.64/plugins/python/helpers/pycharm_display',
'/home/tyarosevich/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7319.64/plugins/python/helpers/third_party/thriftpy',
'/home/tyarosevich/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7319.64/plugins/python/helpers/pydev',
'/home/tyarosevich/anaconda3/envs/test2/lib/python38.zip',
'/home/tyarosevich/anaconda3/envs/test2/lib/python3.8',
'/home/tyarosevich/anaconda3/envs/test2/lib/python3.8/lib-dynload',
'/home/tyarosevich/anaconda3/envs/test2/lib/python3.8/site-packages',
'/home/tyarosevich/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7319.64/plugins/python/helpers/pycharm_matplotlib_backend',
'/home/tyarosevich/anaconda3/envs/test2/lib/python3.8/site-packages/IPython/extensions',
'/home/tyarosevich/code_work/machine_learning_course/NLP/Course 3/Week 1/work'
FROM VSC:
['/home/tyarosevich/anaconda3/bin',
'/home/tyarosevich/anaconda3/lib/python38.zip',
'/home/tyarosevich/anaconda3/lib/python3.8',
'/home/tyarosevich/anaconda3/lib/python3.8/lib-dynload',
'',
'/home/tyarosevich/anaconda3/lib/python3.8/site-packages',
'/home/tyarosevich/anaconda3/lib/python3.8/site-packages/IPython/extensions',
'/home/tyarosevich/.ipython']