I'm on a 64-bit Centos 5 Linux. This comes with Python2.4, but I needed 2.6 or higher to get psycopg2. I installed a virtual environment to run Python2.7.3 (based on this http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/) Now things seem to be working well when I'm logged in as root.
But I need to be able to use the virtualenv as a non-root user, joshmoe. (And start/stop postgresql as this other user)
The command for getting into the virtualenv is:
source /root/Python-2.7.3/projectdir/bin/activate
Understandably, when I run this command as joshmoe, I get a permission denied message:
-bash: /root/Python-2.7.3/projectdir/bin/activate: Permission denied
In an attempt to make this command available to joshmoe, I edited /etc/sudoers to include the following line:
joshmoe ALL=NOPASSWD: /root/Python-2.7.3/projectdir/bin/activate
Now from the joshmoe login, when I run:
sudo source /root/Python-2.7.3/projectdir/bin/activate
I get the following:
sudo: source: command not found
It seems pretty clear to me that I'm not using the sudoers file correctly to specify sourcing this file -- I seem to be giving access to that 'activate' file successfully, but not to the built-in source function. Either of following lines give syntax errors in sudoers:
joshmoe ALL=NOPASSWD: source
joshmoe ALL=NOPASSWD: source /root/Python-2.7.3/projectdir/bin/activate
I've found a good many examples of shudders statements. But I can't figure out the syntax that will make this work. I'm hoping once I get this one, I'll be able to give access to statements like 'service postgresql status' and so forth.
Your problem is that you user doesn't have root access to your virutalenv directory. You need to grant the user access for it to work, for example using:
sudo chmod o+x /root # grant access to root directory
sudo chmod o+rX /root/Python-2.7.3 -R # recursively grant access to everything in Python-2.7.3
source isn't a program, it's a shell butiltin which causes a script to be sourced in the current shell. sudo can only execute programs, not shell builtins, functions or aliases, that's why you get that error.
You can't run source as as sudo source; it's a built-in command for bash, not a program. What you want to do here is probably start a new shell as superuser using sudo -s.
Related
I've prepared a module that's ready to be uploaded to PyPI, the folder 'nester' has all the necessary components. Equipped with the build, dist, MANIFEST, and the two python files (setup.py and nester.py). Whenever I go to admin PowerShell I try running the final command to download it onto my local python file.
python.exe setup.py install
it spits back out 'permission denied', am I putting in the wrong command? the textbook I'm working from is working on terminal while I'm on Windows. The aforementioned textbook inputs
Sudo python3 setup.py install
and it seems to work perfectly for him 😒
here's what happens every time I try to run it
This likely happens, as the installer is trying to write into C:\Program Files directory. Ordinary user accounts do not have permission to do so, as the error Access Denied says.
/In *nix systems, sudo is used to act as root, and root can do anything. Thus permissions aren't an issue in the book sample.)
To illustrate your Windows case, see the image below. In the first case, ordinary user is trying to create test.txt into C:\Program Files. It fails, as expected. The second case does the same, but this time Command Prompt is started with administrative privileges.
As for a fix, you need to run the command in elevated command prompt. The prompt should have window title Administrator: Command Prompt, not C:\Windows\system32\cmd.exe.
I've installed Superset following the installation guide in the apache superset web page, for Python 3.7.
Even though I can manually start the server, when I'm trying to script the startup steps and cron them, it fails.
The output of the execution is the following:
superset: command not found
I've read the replies of this topic but nothing applies to this case.
I'm not using virtualenv for the installation.
These are the output of the which commands:
ec2-user#Superset-STAGE /var/spool/mail$which python3
/usr/bin/python3
ec2-user#Superset-STAGE /var/spool/mail$which superset
~/.local/bin/superset
ec2-user#Superset-STAGE /var/spool/mail$sudo superset
sudo: superset: command not found
Would you please guide me on how to have my script working without failure? Script looks like below.
superset init
wait
superset runserver -d
Cron runs as root, which means its home directory is /root rather than /home/ec2-user as you expect. This means that it will not be able to find /home/ec2-user/.local/bin/superset because it neither looks for executables in a ~/.local/bin/superset nor is it logged in as a user that has such a directory. A quick fix here is to use the full path, but I would recommend moving the executable to a more appropriate directory such as /usr/local/bin and then adding it to the PATH variable in /etc/profile
This is a linux problem that's been stumping me for a while. On my work linux box (running RedHat) I was trying to install some Python packages. However, some funny business is occurring, see below:
This is my objective and first command
pip install scrapylib
This creates a 'Permission Denied' error
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/scrapylib'
My knee-jerk reaction is to put "sudo" in front of the exact same command...
sudo pip install scrapylib
That generates this exception,
sudo: pip: command not found
In order to get around this, I type
sudo su - root
Now this command runs 100% successfully
pip2.7 install scrapylib
Finally, I change back to me
sudo su - uspowpow
Can anyone explain this phenomenon to me? I'm a recent college grad with nothing other than basic Linux knowledge, if someone could explain why placing "sudo" in front of a valid command makes it invalid, I would be extremely grateful (both for the fix and for the knowledge).
This can happen for several reasons. To pick a few:
Your command may not be in the PATH enforced by sudo. For a command in /usr/local/bin (where your pip appears to be), this is downright likely.
Your command may require an alias or shell function to be valid (perhaps you have pip aliased to pip2.7?), or may be a shell builtin itself (though this wouldn't be the case for pip). By default sudo directly invokes children using a member of the execv* family of syscalls, with no shell, so (1) shell functions and aliases aren't invoked under it all; and (2) even if you were using a shell, that shell wouldn't run your current user's dotfiles (being a noninteractive shell, if given a single command to run, it won't run most dotfiles).
To know what the actual cause is, the place to start is to find out what kind of command pip is. To do this, run:
$ type pip
If the answer you get is:
pip is /usr/local/bin/pip
...then you should look at the secure_path value set in your /etc/sudoers to ensure that it contains /usr/local/bin, or just run sudo /usr/local/bin/pip to sidestep the issue. By contrast, if you get:
pip is aliased to `pip2.7'
...then you know the problem is that it's an alias, and you need to run sudo pip2.7 (if the PATH is not also a problem).
I'm using python 3 and have many virtual envs using pyvenv on mac osx 10.9.3. In all of them the command ./ runs my python code. In one of my envs the command has stopped working and I can not find anything about how to get it to begin working again.
EDIT: I get permission denied when typing out the whole file instead of tab (i.e. ./manage.py), and when I add sudo it works, but all the other venvs don't require sudo.
I'm searching through pyvenv docs and searching through various bash links but can't get it to restore or know where that shortcut comes from.
When I type python [file] everything works as expected, but I want to restore the ./[file] I know it's going to be something easy but for some reason I can't figure out what to search to get the relevant solution.
When you type ./[tab] and the file you're expecting doesn't come in linux shell, chances are you need to make the file executable:
sudo chmod a+x manage.py
Or you don't have sufficient permissions to access the file:
sudo chown user:group manage.py
(Be careful with the last one because it may lead to unexpected behaviour)
I am trying to get the python-connect-mysql module to run, but when I execute python setup.py install on my command shell, I receive the following error:
[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-2259.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Python/2.7/site-packages/
I have Python 3.2 installed and need to install to /Library/Python/3.2/site-packages/
I have looked through many solutions, but do not understand the command shell very well. I tried the following to edit my bash_profile and received an error saying the file didn't exist:
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.bash_profile
Then I tried: touch ~/.bash_profile but didn't know what to do once I got there--the blog I read had very sketchy instructions--so I hit exit and it logged me out.
This seems to be the biggest hurdle for me to download third party packages. I tried the sudo /Applications/TextEdit.app... method again to see if the terminal would let me open up the bash_profile since I had touched it and received an error message that I do not have permission to open the file. Can someone please help? I am going crazy!
While using sudo is a possibility, you should always use virtualenv to manage your python modules in case somebody decides to replace setup.py with some kind of malicious code (and seriously, who looks at the code of setup.py everytime when installing a new module) that giving root rights to execute wouldn't exactly benefit your system.
Try using the Python 3 executable with elevated rights:
sudo python3 setup.py install
The path /Library/Python/* is used to store python modules available for all your system globally, and these directories are created from root user, that's why you get the "permission denied" error. Just use sudo.
sudo python setup.py install
Also you may have a look at virtualenv