Unable to install YAML for Python2.7 on my mac - python

I am trying to install YAML module (PyYAML3.10) for Python 2.7 on my mac. I get the foll error message:
$ python setup.py install
running install
running build
running build_py
running build_ext
running install_lib
creating /Library/Python/2.7/site-packages/yaml
error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied
Can anyone help me out with this?
Thanks!

It's a matter of permissions... Try with: sudo python setup.py install

The error is very clear:
error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied
You don't have permission to write to this directory. If you run setup.py using sudo, you'll run it with root privileges, which will let you install it:
sudo python setup.py install
You may want to look into something like macports, which gives you a convenient way of installing (and uninstalling, ugrading, etc) a variety of open source software. It includes packaged versions of the YAML module.

I would suggest that you use pip to install the package and virtualenv to make pip install packages as your user. This way you won't get anymore Permission denied messages. See this guide for learning more about virtualenv. It might seem a bit hard to grip at first but I promise you that the effort is well worth it.

Related

Errno 13 Permission denied, in WSL, virtualenv, even as root

I'm using Windows Subsystem for Linux, running Debian, upgraded to Buster. I configured Visual Studio Code with remote development as well. Uninstalled python2.7, and made python3 as my default by creating a symlink /usr/bin/python -> /usr/bin/python3.
So, in my home directory, as the current user I create a virtualenv: python -m virtualenv -p python3 venv, and all is fine.
I then proceed to activate it. I use fish mostly, but this problem is also when running bash. source venv/bin/activate.fish. All is fine, it works.
Then, I try to install my package python setup.py install, and it works fine:
running install
running bdist_egg
running egg_info
writing myproj.egg-info/PKG-INFO writing dependency_links to myproj.egg-info/dependency_links.txt
...
And then it proceeds to installing dependencies.
Reading https://pypi.org/simple/jmespath/
Downloading https://files.pythonhosted.org/packages/83/94/7179c3832a6d45b266ddb2aac329e101367fbdb11f425f13771d27f225bb/jmespath-0.9.4-py2.py3-none-any.whl#sha256=3720a4b1bd659dd2eecad0666459b9788813e032b83e7ba58578e48254e0a0e6
Best match: jmespath 0.9.4
Processing jmespath-0.9.4-py2.py3-none-any.whl
Installing jmespath-0.9.4-py2.py3-none-any.whl to /home/ap/projects/myproj/venv/lib/python3.7/site-packages
error: [Errno 13] Permission denied: '/home/ap/projects/myproj/venv/lib/python3.7/site-packages/jmespath-0.9.4-py3.7.egg/jmespath-0.9.4.dist-info' -> '/home/ap/projects/myproj/venv/lib/python3.7/site-packages/jmespath-0.9.4-py3.7.egg/EGG-INFO'
All directories have permissions, I'm the owner, and creating the symlink from the CLI works. I even tried to do this by first elevating permissions with sudo su, and still getting "Permission denied".
I tried downgrading pip and setuptools by a major version but it didn't help. I've been doing this on Linux countless times and it all worked fine, I just don't get what might be the cause for this.
pip list output:
Package Version
---------- -------
pip 19.2.1
setuptools 41.0.1
wheel 0.33.4
Apparently this was because the underlying file system is NTFS, and Linux handles open files differently from Windows. Once a file was open, from WSL, apparently there was a lock on it, and it can't be overwritten. So the only thing that worked was to close Visual Studio Code, do the install, upgrade, whatever, then re-open it.
This is a wild hunch, so take it with a grain of salt.

Python setup.py without root

I would like to install some Python module, namely the MATLAB Engine. MATLAB is installed globally under /usr/local/sw/matlab, so I change to the corresponding directory and then run setup.py as explained in the linked documentation. However, I am not root, so I added the --user flag, as documented by the official Python Docs.
So this is what I get:
> python setup.py install --user
running install
running build
running build_py
creating build
error: could not create 'build': Permission denied
Apparently it tries to build the module in the current directory, where I have no write access. I can sidestep this by running
python setup.py build --build-base=/path/to/temp/build/dir
But then I don't know how to install that. Also I cannot combine those 2 approaches as install does not recognize the --build-base option.
I furthermore tried to copy the whole matlabroot/extern/engines/python directory somewhere else and run python setup.py install --user there, but this yields
error: The installation of MATLAB is corrupted. Please reinstall MATLAB or contact Technical Support for assistance.
I guess it does not find the matlabroot anymore.
So how do I build and install some source located somewhere under /usr... without being root?
You can use Virtualenv or venv to deal with this kind of issues.
Edit: As we went a bit deeper into issue itself, we managed to figure out the answer.
If you wish to use virtual environment: python setup.py build --build-base="/path/to/directory_you_can_write_to" install --prefix="/path/to/virtualenv/" --user
If you wish to accomplish what #Feodoran asked for: python setup.py build --build-base="/path/to/directory_you_can_write_to" install --user
Useful links:
https://de.mathworks.com/help/matlab/matlab_external/install-matlab-engine-api-for-python-in-nondefault-locations.html
https://python.org/3.2/install

Installing pyobjc on a Mac

I am facing problems installing pyobjc on my mac.
Basically I have to install pyobjc on a new Mac System in the system default python. I have so far tried easy_install, pip and downloading the pkg file and installing. All give me a error in different ways. Some give me a error saying certain safari files are missing other cant due to some permission being denied even though I am running them through sudo su.
I then found a fix.
pip install pyobjc --user
This worked and I could access all the modules I required, but then if I try running python through sudo, I cant access those modules.
Can anyone suggest a fix for this.
NOTE: I don't mind a different method to install also. Also I have not tried brew due to some previous difficulties with it.
NOTE 2: I need to be able to access those modules using all users on the computer, the root user and me(the non-root user)
i had to (temporarily) move (using sudo) /Library/Python/2.7/site-packages/Extras.pth to another name before I could install the current pyobjc.
This is what works for me:
sudo mv /Library/Python/2.7/site-packages/Extras.pth /Library/Python/2.7/site-packages/Extras.pth_orig
pip install --upgrade pyobjc
sudo mv /Library/Python/2.7/site-packages/Extras.pth_orig /Library/Python/2.7/site-packages/Extras.pth
It appears that something in the .pth file interferes with the install, but does not impede running pyobjc.
but then if I try running python through sudo, I cant access those
modules.
Because sudo python basically means run python as some other user (root by default). That user may have a different set of environment variables, including $PATH.
Some of linux distributions use older Python version for root user,like centos.If the Python verison you're running with sudo isn't correct,you can't access those modules installed by pip.
So in my opinion,if you didn't get permission issues,you don't need to use sudo ,using sudo might bring unexpected mistakes(most environment variables issues),maybe chown or chmod can fix those issues.
So here are my plans:
Plan A: The best way is to try to use virtualenv.
Plan B: Install modules without sudo command,if got permission errors(not very common),try --user .
Install to the Python user install directory for your platform.
Typically ~/.local/, or %APPDATA%Python on Windows.
In most cases,you should modify your PYTHONPATH.See details from How do I access packages installed by pip --user.
Plan C: All related commands are executed with sudo.sudo pip install (all modules) and sudo python script.py.Not a good idea.

Building wheel for package failed: Permission denied when using pip in virtualenv wrapper

Recently I try to learn the virtualenv wrapper, and I also read some posts on SO, but still don't know what's the best way to solve my problem...
The following is the steps I create an environment and using pip to install package.
mkvirtualenv -p python3 envtest
pip install markdown
However the stdout shows the following message:
Building wheel for markdown failed: [Errno13] Permission denied: '/Users/haha/Library/Caches/pip/wheels/ee'
while I can just use the following command to change the owner of the folder from root to haha:
sudo chown haha wheels
But I don't know is that the most correct way to handle this situation?
Since originally I thought virtualenv wrapper should not touch any global folder like something under Library folder?
p.s. I use MAC OS X
Thanks in advance.
I got stuck in a similar error, and I solved this with something like this:
$ pip install markdown --no-cache-dir
If you run pip --help you will find:
--no-cache-dir Disable the cache.
Hope that it can help to someone in the future.

python mysql configuration problem

I'm trying to make django work on snow leopard. So far I've installed mysql 64 bit installed python 2.7 64 bit and installed django 1.2.1. Now I'm trying to install mysql-python-1.2.3; at the beginning I had problems because I hadn't installed the setup tool, having done that when try to install it by executing these command
python setup.py build
python setup.py install
here's what I got
running build
running build_py
creating build/lib.macosx-10.5-fat3-2.7
error: could not create 'build/lib.macosx-10.5-fat3-2.7': Permission denied
Any idea?
Am I doing something wrong?
Thanks
Mauro
You need to use sudo
sudo setup.py build
sudo setup.py install
You might just want to use sqlite.
At the risk of pointing out the obvious, you do not have permission to write to the build directory. Check and change the directory permissions (with the chmod command) or do the setup as an admin user.

Categories