1

I have requests module installed and I have tested through virtual python environment this program and it works(as in prints the right answer).

import requests
payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
r = requests.get('http://httpbin.org/get', params=payload)
print(r.url)

But when this program is in /public_html/wp-content/plugins I get ImportError: No module named requests so I figured that the problem might be because PYTHONPATH environment variable is not set properly, so I created in /public_html/wp-content/plugins/path __init__.py, empty py file, and added to the end of .bashrc export PYTHONPATH=${PYTHONPATH}:/public_html/wp-content/plugins/path, then run source ~/.bashrc command through ssh to reset it. Python program still gives me that error, I have used this Permanently add a directory to PYTHONPATH to help me to change Pythonpath.

Am I approaching this issue wrong way, or am I missing something when trying to change PYTHONPATH, what the problem could be? Thanks for reading.

EDIT: I have fixed the problem, what I had to do is just install those modules into the file that has scripts that need to be executed, but now I have another problem, the server is executing those scripts automatically as python, but they need to be executed as python3, maybe you know how could this be changed? Thanks.

Community
  • 1
  • 1
MakeMeWise
  • 31
  • 1
  • 7
  • If you are using virtualenv or virtualenvwrapper, you have installed requests in an area that is not on the system path. Your program can be in any directory, you just must be in the virtual environment. Tell me about your virtual environment setup – joel goldstick Jul 09 '16 at 11:47
  • @joelgoldstick Thanks for your response, to set up my environment I did everything exactly what this guide said https://www.godaddy.com/garage/tech/config/how-to-install-and-configure-python-on-a-hosted-server/. – MakeMeWise Jul 09 '16 at 12:11
  • @joelgoldstick Thank you for your help, I have fixed the problem, what I had to do is just install those modules into the file that has scripts that need to be executed, but now I have another problem, the server is executing those scripts automatically as `python`, but they need to be executed as `python3`, maybe you know how could this be changed? – MakeMeWise Jul 09 '16 at 15:10

0 Answers0