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
请先登录再写评论。
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.
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
whereas a working path is like this
Best regards,
Thomas
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.:
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
Glad it helped! Thanks, Merry Christmas to you, too!