2

When I run python abc.py it runs fine

But when I do sudo python abc.py then it shows some packages missing error. Of the several import errors, here's the one:

ImportError: No module named numpy

Why?

What I think is that those packages are installed with normal user(ubuntu) permissions and not root permissions. If this is the case, how should I get over with this? Do I have to install all the packages again with root access?

Note: everything I discussed here is w.r.t ec2 linux ubuntu machine

2
  • What do you mean by "Installed with normal user permissions"? How did you install the package? You should either install it via Ubuntu's package manager (apt-get) or via easy_install or pip as root. Commented Oct 12, 2016 at 11:25
  • I installed packages using pip install package-name worked for me Commented Oct 12, 2016 at 11:26

1 Answer 1

1

The sudo environment may not contain your PYTHONPATH

/etc/sudoers contains Defaults env_reset. Simply add Defaults env_keep += "PYTHONPATH" to /etc/sudoers and it will work just fine with sudo.

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

5 Comments

it says W10: Warning: Changing a readonly file will that not cause any problem?
read this - how to edit sudoers: digitalocean.com/community/tutorials/…
this is not working for me, when i do echo $PYTHONPATH this is giving me no output - BLANK
python on the system was installed using Anaconda in the system
Try this: add export PYTHONPATH=/your/custom/path to ~/.bashrc or /etc/bash.bashrc. add PYTHONPATH to Defaults env_keep += "ENV1 ENV2 ..." in sudoers file. remove Defaults !env_reset from sudoers file if present

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.