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
Related
I'm taking a class on Coursera, this is what it's asking me to do.
brew info python
The section you are interested in is the location of where it was
installed.
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /opt/homebrew/opt/python#3.9/libexec/bin
The /opt/homebrew/opt/python#3.x/libexec/bin is the one you want to
use and set for your path. Copy it from the terminal. Depending on the
version of Mac OS you are running the next steps may vary slightly.
When I enter in: /opt/homebrew/opt/python#3.9/libexec/bin
I get this:
zsh: permission denied: /opt/homebrew/opt/python#3.9/libexec/bin
Can anyone help?
You're not supposed to execute /opt/homebrew/opt/python#3.9/libexec/bin as an actual command. It's a directory.
You're supposed to add it to your PATH environment variable, so that you can run the commands contained in that directory.
Add this line to your ~/.zshrc file:
typeset -x PATH=/opt/homebrew/opt/python#3.9/libexec/bin:$PATH
Our server was updated to use the NFS system, and the previous /scratch path is now mapped to /local/scratch. My anaconda3 was installed under /scratch/xxx/anaconda3, which basically means it is now under /local/scratch/xxx/anaconda3. Intuitively, I have updated the PATH variable in .bash_profile, and running which conda actually gives me
/local/scratch/xxx/anaconda3/bin/conda
However, when I actually tried to run $conda, the system reports the error below:
-bash: /scratch/xxx/anaconda3/bin/conda: No such file or directory
which is quite weird and indicates an inconsistency with the result returned by which conda.
In addition, I tried to directly cd into /local/scratch/xxx/anaconda3/bin/ and execute $./conda. It reports
-bash: ./conda: /scratch/xxx/anaconda3/bin/python: bad interpreter: No such file or directory
My wild guess is that in addition to the environment variable in .bash_profile, there are some internal settings of anaconda stored elsewhere, because the system actually knows the right path for python, while conda tries to execute python from the old path (i.e., /scratch/xxx/anaconda3/bin/python in the above error message). However, I couldn't seemingly find this file and change it to get things work.
Somehow, I feel this should be a common issue, however, I did not find any solutions from the internet. Any suggestions would be greatly appreciated.
I have fixed my issue using cpr (credits to #merv). Here I post the detailed instructions, so if some one has the same problem, he/she can almost just follow them to get things fixed.
1. Installation
According to anaconda.org, the recommended command to install cpr is
$ conda install -c anaconda conda-prefix-replacement
You may find this to be actually very awkward; the reason we need cpr is that our conda is broken due to the prefix issue, if we can run conda command to install cpr, then why should we need cpr?
Instead, we may install cpr directly from github:
$ git clone https://github.com/conda/conda-prefix-replacement.git
$ cd conda-prefix-replacement
$ python setup.py install
2. Rehome
After installation, running the rehome command to fix the prefix issue is quite straightforward. Say your anaconda is moving from path_A to path_B, simply do
$ cpr rehome path_B --old-prefix path_A
In my case, the command should be
$ cpr rehome /local/scratch/xxx/anaconda3 --old-prefix /scratch/xxx/anaconda3
After running the cpr command, exit the terminal and re-login. Everything should be good now!
I am trying to distribute a Python script of mine using PyInstaller on MacOSX. I am trying to use PyInstaller with the packages installed on my virtual environment using Python's innate venv package.
My virtual environment directory is named venv in this instance.
I am following PyInstaller's instructions to do so, found here: https://pythonhosted.org/PyInstaller/usage.html
However, when I run
./venv/bin pyinstaller <SCRIPTNAME> --onefile
The command prompt spits out this error:
zsh: permission denied: ./venv/bin
The only other examples of my problem occurred with users who altered their permissions prior to the problem arising, not when dealing with virtual environments, so I haven't been able to find a
proper solution for my case.
Am I using PyInstaller with the venv incorrectly, or how do I give myself the permission needed to run the correct command?
Hmm where you able to do
source bin/activate
This is required in order to add that source into the permissions lists as +x in your venv.
For more information please refer to [1]
Hope this helps
[1] https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
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 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.