I recently found out you can run python from emacs (Python Mode -> py-shell) and I've been running my scripts through the py-shell due to only needing to C-c C-c, but I've been running into a problem:

I import requests among other external libraries I have installed (through pip), but the python shell in Emacs can't find the modules. Is there a way I can change PATH variables in such a way that Emacs finds these modules?

Here's the error the python shell gives (not sure if it helps, but this runs on the "Py:run Shell-Compile" buffer):

exec(compile(open(r'/Users/r/Desktop/name.py').read(), r'/Users/r/Desktop/name.py', 'exec')) # PYTHON-MODE
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/r/Desktop/name.py", line 1, in <module>
    import requests
ImportError: No module named requests

(As proof that I do have requests installed, I ran this on the terminal with python name.py and it worked as expected)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.