PyCharm Debugger and Python console do not find enironment anymore

已回答

Hi,

 

I have PyCharm Pro running on MacOS and I have several projects in parallel. All of them are running fine, but one started to make problems the last days. When I open the debugger I get the error message (traceback)

Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 13, in <module>
import traceback
ModuleNotFoundError: No module named 'traceback'

So it looks like the environment is not set properly (I use virtualenv). When I start Pycharm I can open Python Console and it works, i.e. I can import traceback in there without error (and also other installed modules).

When I try to run the project it doesn't find those modules.

I tried everything to fix that but was unsuccessful, any hint will be greatly appreciated.

 

Best regards,

Thomas

 

0

Hi! Does the Run work as expected? Please make sure there is no custom modules/packages that have the same name as built-ins/packages installed from PyPI.

0
Avatar
Permanently deleted user

Hi Pavel,

thank you for your answer! 

The run had the same problem however I have managed to get it somehow working again by disabling "Add content root to PYTHONPATH". 

Unfortunately my top level directory of my modules is named <project root>/site from where I think the problems might come from. But renaming this directory did not help either. 

Do you know what the above options does as I found out that my sys.path is completely damaged when this option is switched on (even though it is active in other projects and the path is not damaged there).

My damaged path looks like

 

/Users/hant/work/python/virtualenvs/cw-system/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 59072 --file /Users/hant/work/python/projects/cw-system/site/api/root.py 
/Applications/PyCharm.app/Contents/helpers/pydev
/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend
/Users/hant/work/python/projects/cw-system
/Applications/PyCharm.app/Contents/helpers/pydev
/Users/hant/Library/Caches/PyCharm2017.3/cythonExtensions
/Users/hant/work/python/virtualenvs/cw-system/bin/../lib/python36.zip
/Users/hant/work/python/virtualenvs/cw-system/bin/../lib/python3.6
/Users/hant/work/python/virtualenvs/cw-system/bin/../lib/python3.6
/Users/hant/work/python/virtualenvs/cw-system/bin/../lib/python3.6/lib-dynload

whereas a working path is like this

/Users/hant/work/python/virtualenvs/test/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 59056 --file /Users/hant/work/python/projects/test/test.py 
/Applications/PyCharm.app/Contents/helpers/pydev
/Users/hant/work/python/projects/test
/Users/hant/work/python/projects/test/modules
/Applications/PyCharm.app/Contents/helpers/pydev
/Users/hant/Library/Caches/PyCharm2017.3/cythonExtensions
/Users/hant/work/python/virtualenvs/test/lib/python36.zip
/Users/hant/work/python/virtualenvs/test/lib/python3.6
/Users/hant/work/python/virtualenvs/test/lib/python3.6/lib-dynload
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6
/Users/hant/work/python/virtualenvs/test/lib/python3.6/site-packages
/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend

Best regards,

Thomas

 

 

0

This option adds any folders from Settings | Project ... | Project Structure (content roots list on the left) to PYTHONPATH. Make sure there are no unexpected values there, by default, there is only one entry - current project root, e.g.:

0
Avatar
Permanently deleted user

Hi Pavel,

thanks a lot for your comprehensive answer! So I guess that my problem is the module directory 'site' which interferes with Python's site.py 

Just wondering why renaming that directory didn't help.

Thank you for your help!

Wish you a merry christmas!

 

Best regards,

Thomas

0

Glad it helped! Thanks, Merry Christmas to you, too!

0

请先登录再写评论。