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!!

  • 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`](https://github.com/pyenv/pyenv) instead. `pyenv` + [`virtualenv`](https://github.com/pyenv/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. – xgord Jan 27 '18 at 20:04
  • Are the system's Python and the PyCharm interpreter different? – Joe Jan 27 '18 at 21:22
  • Please try to find out which is the executable used by the interpreter `import sys; print(sys.executable);` (https://stackoverflow.com/questions/2589711/find-full-path-of-the-python-interpreter) – Joe Jan 27 '18 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! – photonic_engineer Jan 27 '18 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. – Joe Jan 27 '18 at 22:57
  • @Joe, executing `/usr/bin/python2.7` and `/usr/bin/python` both resulted in the same output, `Python 2.7.13 (default, Nov 24 2017, 17:33:09) `. Actually I was able to get Pycharm working by adding `sys.path.insert(1, '/usr/lib/python2.7/dist-packages')` to near the start of my code. Thanks so much for the help! – photonic_engineer Jan 27 '18 at 23:09

1 Answers1

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)