For a number of reasons - the main one being thatEmacs is amazing! - I am trying to do all my Python development at work in Emacs instead of Pycharm, which I was using previously.
The one component I have not been able to get running right in Emacs is the debugger. I have been trying to usepdb in emacs to debug the application I am working on, but I haven't been able to figure out how to getpdb to find all the necessary modules. Instead, when I run my__main__.py file through pdb, I get a bunch of import errors because it can't find the modules for the project. If I manually add the appropriate paths tosys.paths and then import the modules one by one from the interactive pdb prompt, this works, but obviously is not the right solution.
In the Pycharm debugger there are two options: "add content roots to PYTHONPATH" and "add source roots to PYTHONPATH", which configure this stuff automatically. My issue is that I haven't figured out how to configure equivalent options in Emacs - i.e., I am not sure how/where to set PYTHONPATH so thatpdb within Emacs recognizes it. I have tried setting it a few different was in my Emacs config, but nothing seems to work. Any suggestions? Thank you!
- 1What about
(setenv "PYTHONPATH" "/the/python/path")in your init file?Nsukami _– Nsukami _2015-11-18 17:08:38 +00:00CommentedNov 18, 2015 at 17:08 - That did it actually! This was one of the first solutions that I tried, but it turned out I had entered the wrong path! If you put this as an answer I will accept it as the correct one.elethan– elethan2015-11-18 17:28:00 +00:00CommentedNov 18, 2015 at 17:28
1 Answer1
I am not sure how/where to set PYTHONPATH
To inform Emacs about your PYTHONPATH, just edit your init file and add this line:
(setenv "PYTHONPATH" "/the/python/path")
- Could you please elaborate? Where can I find my python path, do I need to restart emacs before setenv starts working? I have tried a couple of paths already (from
which pythonin the terminal or from just importing modules in an interactive shell and getting part of the module address, but I've had no success so far)Leo Azevedo– Leo Azevedo2016-04-30 05:36:29 +00:00CommentedApr 30, 2016 at 5:36 - @LeoAzevedo The value returned by
which pythonis not your PYTHONPATH. Open a terminal, and typeecho $PYTHONPATH. Replace "/the/python/path" in my answer, by the printed value. Let me know.Nsukami _– Nsukami _2016-04-30 11:43:18 +00:00CommentedApr 30, 2016 at 11:43 - echo $PYTHONPATH returns nothing literally in my Terminal. However, which python returns Users/user/opt/anaconda3/bin/python3Emmanuel Goldstein– Emmanuel Goldstein2021-05-30 06:29:34 +00:00CommentedMay 30, 2021 at 6:29
Explore related questions
See similar questions with these tags.

