python only works with sudo

2024/11/16 0:34:21

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

  • pip uninstall then pip install for pandas, numpy, and scipy as noted in Python Pandas - Missing required dependencies ['numpy'] 1
    • the above using flags --upgrade and --user to try to get the packages to apply to my user account rather than root.
  • deleting all files with .pyc in the directory as in ImportError: Missing required dependencies ['numpy']
  • Adding PATH="${PATH}:/path/to/user/python/packages and PYTHONPATH="${PYTHONPATH}:/path/to/user/python/packages" in my .bashrc file

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

Answer

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)

https://en.xdnf.cn/q/71730.html

Related Q&A

Forbidden (CSRF token missing or incorrect) Django error

I am very new to Django. The name of my project is rango and I have created a URL named /rango/tagger that is supposed to send an object. In my java-script, I have tried to communicate with this route …

How to update artists in scrollable, matplotlib and multiplot

Im trying to create a scrollable multiplot based on the answer to this question: Creating a scrollable multiplot with pythons pylabLines created using ax.plot() are updating correctly, however Im unabl…

Sending Keys Using Splinter

I want to test an autocomplete box using Splinter. I need to send the down and enter keys through to the browser but Im having trouble doing this. I am currently finding an input box and typing tes int…

Split lists within dataframe column into multiple columns [duplicate]

This question already has answers here:Split a Pandas column of lists into multiple columns(13 answers)Closed 3 years ago.I have a Pandas DataFrame column with multiple lists within a list. Something l…

Drawing with turtle(python) using PyCharm

Im running the latest PyCharm Pro version and trying to run the below code from a scratch file but it doesnt seem to work import turtlewn = turtle.Screen() alex = turtle.Turtle() alex.forward(150) a…

How to adapt my current splash screen to allow other pieces of my code to run in the background?

Currently I have a splash screen in place. However, it does not work as a real splash screen - as it halts the execution of the rest of the code (instead of allowing them to run in the background).This…

Reversed array slice including the first element [duplicate]

This question already has answers here:Python reverse-stride slicing(8 answers)Closed 5 years ago.Lets say I have:>>> a = [1, 2, 3, 4]And I want to get a reversed slice. Lets say I want the 1s…

Problem using py2app with the lxml package

I am trying to use py2app to generate a standalone application from some Python scripts. The Python uses the lxml package, and Ive found that I have to specify this explicitly in the setup.py file that…

How to run TensorFlow on AMD/ATI GPU?

After reading this tutorial https://www.tensorflow.org/guide/using_gpu I checked GPU session on this simple code import numpy as np import matplotlib.pyplot as plt import tensorflow as tfa = tf.constan…

Pure virtual function call

Im using boost.python to make python-modules written in c++. I have some base class with pure virtual functions which I have exported like this:class Base {virtual int getPosition() = 0; };boost::pytho…