1

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!

askedNov 18, 2015 at 15:51
elethan's user avatar
2
  • 1
    What about(setenv "PYTHONPATH" "/the/python/path") in your init file?CommentedNov 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.CommentedNov 18, 2015 at 17:28

1 Answer1

1

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")

answeredNov 18, 2015 at 18:49
Nsukami _'s user avatar
3
  • 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 (fromwhich python in 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)CommentedApr 30, 2016 at 5:36
  • @LeoAzevedo The value returned bywhich python is not your PYTHONPATH. Open a terminal, and typeecho $PYTHONPATH. Replace "/the/python/path" in my answer, by the printed value. Let me know.CommentedApr 30, 2016 at 11:43
  • echo $PYTHONPATH returns nothing literally in my Terminal. However, which python returns Users/user/opt/anaconda3/bin/python3CommentedMay 30, 2021 at 6:29

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.