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
Related
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 just downloaded a python package and installed it on a Linux box using the following command:
python setup.py install --prefix=/home/ubuntu/dev/git/nx
That is, I did not use the default install directory. I then appended the existing PYTHONPATH variable in ~/.bashrc as follows:
export PYTHONPATH=/some/previous/path:/home/ubuntu/dev/git/nx
But when I run import of the package in python, I get a ImportError: No module named error.
Am I specifying the wrong path in PYTHONPATH? If so, how do I figure out which path to put there? Or is there a different error?
Thx
If you put it in bashrc you will either need to source ~/.bashrc or log in again. Depending on your distro, bashrc might not be the right place to put it. You're using Ubuntu, so it will work.
It's also generally good practice to include the current variable when exporting a path-type variable.
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/dev/git/nx
You can verify that your path is correct with echo $PYTHONPATH. You can also run the above command to see if it will fix it (albeit temporarily and only in your current shell).
Ran
sudo python setup.py install
Didn't have to mess with PYTHONPATH. Working great!
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