6

My python 2.7 script works on my Ubuntu system if I call it using

sudo python [filename].py

or from a bash script using

sudo ./[bashscriptname].sh

But if I call it from Pycharm I get oauth errors, and from the command prompt

python [filename].py 

throws an error on the 'import pandas' line:

ImportError: Missing required dependencies ['numpy', 'pytz']

I've tried

But nothing seems to work.

pip list

Shows all the necessary pandas, numpy, pytz, and oauth packages.

I've a noob who has spent nearly a day on this--help would be very greatly appreciated!!

6
  • 2
    Sounds like somewhere along your install chain you might have run sudo on something that shouldn't have (like pip). You might want to start over from scratch with your python install and go with using pyenv instead. pyenv + virtualenv allow a good way of using python as a non-sudoer and pip installing packages. Plus, it lets you have different python package setups. Commented Jan 27, 2018 at 20:04
  • Are the system's Python and the PyCharm interpreter different? Commented Jan 27, 2018 at 21:22
  • Please try to find out which is the executable used by the interpreter import sys; print(sys.executable); (stackoverflow.com/questions/2589711/…) Commented Jan 27, 2018 at 21:24
  • I get "/usr/bin/python2.7" when I run joe's suggestion from PyCharm. When I run python from the command prompt, I get "/usr/local/bin/python". Finally, when I run sudo and the command prompt, I get "/usr/bin/python". No wonder I'm having issues! Commented Jan 27, 2018 at 21:44
  • Could you just start these binaries from the command line and try something similar to what you are doing in your script? /usr/bin/python2.7 and /usr/bin/python might be the same. Could you check if one or two of the binaries is a symbolic link to the others? Btw, what are you doing in your script? Could you paste some of the code? And try to see if it works if you start PyCharm with sudo and execute it then. Commented Jan 27, 2018 at 22:57

1 Answer 1

0

My band-aid solution was to notice that when I tried a sudo pip install pandas, I got a notice: Requirement already satisfied: pandas in /usr/lib/python2.7/dist-packages

I stuck a sys.path.insert(1, '/usr/lib/python2.7/dist-packages') near the top of my script and it's now working okay.

Thanks tremendously to @Joe!!

My next steps are a complete do-over of my python install, hopefully without the sudos... (thank you @xgord)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.