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

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.

Related

permission denied when installing python packages through cygwin

I'm working on a windows 7 and using Cygwin for unix-like functionality. I can write and run Python scripts fine from the Cygwin console, and the installation of Python packages using pip installis successful and the installed package appears under pip list. However, if I try to run a script that imports these packages, for example the 'aloe' package, I get the error "no such module named 'aloe'".
I have discovered that the packages are being installed to c:\python27\lib\site-packages, i.e. the computer's general list of python packages, and not to /usr/lib/python3.6/site-packages, i.e. the list of python packages available within Cygwin. I don't know how to rectify this though. If I try to specify the install location using easy_install-3.6 aloe I get the error
[Errno 13] Permission denied: '/usr/lib/python3.6/site-packages/test-easy-install-7592.write-test'.
In desperation also tried directly copying the 'aloe' directory to the Cygwin Python packages directory using cmd with cp -r \python27\lib\site-packages\aloe \cygwin\lib\python3.6\site-packages and the move was successful, but the problem persists and when I check in the Cygwin console using ls /usr/lib/python3.6/site-packages I can't see 'aloe'.
I have admin rights to the computer in general (sudo is not available in Cygwin anyway) so really can't figure out what the problem is. Any help would be greatly appreciated.
Thanks.
just make sure you are in admin mode.
i.e. right click on Cygwin, select running as administrator.
then install your package specifically using pip3, for python3.
i.e. pip3 install your_package
with updated version, do pip3 install --upgrade your_package

Python 3.4.2 AND pip Permission Issues

I've been struggling with an issue with Python and pip installs (python version 3.4.2, same with x86 or x64 MSIs, Windows 7 x64). I'm using the CPython installer available from the Python.org website.
When I install, I get the UAC prompt, which I approve, and it installs fine to D:\opt\python34 (along with pip, as added in 3.4.2 installations by default). Then, as standard procedure, I add the install path and Scripts subfolder to the user path variable. Now, the issues are as follows:
Whenever I run python setup.py install inside any package directory, the prompt hangs at writing ... to top_level.txt or writing to dependency_links.txt or etc. (Same issue happens if I create a virtual environment using python -m venv, activate it, and do python setup.py install). Setup.py never succeeds. Pip install also hangs infinitely after giving a warning "manifest_maker: Standard file '-c' not found."
If I remove setuptools, and just use distribute, then "python setup.py install" works.
Kindly assist with ideas/solutions.
After many days of trying a workaround, I finally got down to debugging the setup.py script and setuptools and distutils. Figured out the problem was a missing "svn.exe" on my workstation, which caused the "svn_finder" function in setuptools core to hang up.
Can someone point me in the right direction as to how I can make the right team aware of the "bug"?

how to setup twist 14.0.0 for Python 2.7.8

I am following a tutorial on communicate TCP using twisted with Python. When I ran my code module it failed on the first line:
ImportError: No module named twisted.internet.protocol
So I guess there is no twisted install with my current of python 2.7.8. I am using Mac OS X 10.9.8.
So I tried to install twisted and version I found is tarball 14.0.0.
I install from terminal with command line:
sudo python setup.py install.
And everything look OK to me.
Now I ran the code module and I still have the same error. I guess I need to configure the new install twisted with python. I am looking for a guidance but still no luck yet.
When you ran:
sudo python setup.py install
You may well have screwed up your system.
setup.py install scribbles random files onto random pieces of your filesystem. Your OS maintainer has certain ideas about what files should exist in the "system" part of your system - loosely speaking, the part outside of the "home directory" area. When you run setup.py install using sudo you give it permission to write files of this "system" area. There's a reason normal users aren't allowed to write files there.
Perhaps some critical system service depends on a certain version of a Python library and this sudo python setup.py install command replaces the installed version (the version that your OS maintainer installed and shipped to you) with a different, incompatible version.
Or perhaps it's not a critical system service, maybe it's just one of the programs you use from time to time. Either way, it's now broken.
Never, never, never, never, never run that command. It doesn't matter what package you're thinking about installing: this is the wrong way to install it.
You should probably wipe your host and do a fresh install of your OS. Unfortunately this drastic solution is the most straightforward. setup.py install does not keep a record of what files it wrote or where. You can try to undo whatever damage it did, but figuring out what that damage is is complicated (beyond the scope of this answer) and time-consuming.
Then, install virtualenv and/or virtualenv wrapper. Then create a virtual environment, activate it, and install the desired Python packages into the environment.
virtualenv gives you isolated Python environments that don't interfere with each other or with your system Python. You can have as many of them as you want. They're cheap to create and if things go wrong you can easily destroy them and start over again.
Here's what the process looks like on Linux:
exarkun#top:/tmp$ virtualenv virtualenv-demo
New python executable in virtualenv-demo/bin/python
Installing setuptools, pip...done.
exarkun#top:/tmp$ . virtualenv-demo/bin/activate
(virtualenv-demo)exarkun#top:/tmp$ pip install twisted
Downloading/unpacking twisted
Using download cache from /home/exarkun/.pip/download-cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FT%2FTwisted%2FTwisted-14.0.0.tar.bz2
Running setup.py (path:/tmp/virtualenv-demo/build/twisted/setup.py) egg_info for package twisted
Downloading/unpacking zope.interface>=3.6.0 (from twisted)
.
.
.
Installing /tmp/virtualenv-demo/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-nspkg.pth
Successfully installed twisted zope.interface
Cleaning up...
(virtualenv-demo)exarkun#top:/tmp$

Why can't I install setuptools on my Centos 6 VPS?

I'm trying to install setuptools for Python2.7 on a Centos 6 VPS with Digital Ocean using this tutorial. When I reach the step where you "Intall setuptools using the Python we've installed (2.7.6)", I get this error:
[username#hotsname setuptools-1.4.2]$ python2.7 setup.py install
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/test-easy-install-1111.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/local/lib/python2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
https://pythonhosted.org/setuptools/easy_install.html
Please make the appropriate changes for your system and try again.
Now, I previously followed instructions on the same digital ocean community site to give the user executing the above root privileges. When I try to use sudo to do this task, I get:
[username#hostname setuptools-1.4.2]$ sudo python2.7 setup.py install
[sudo] password for username:
sudo: python2.7: command not found
So I'm a little confused. I feel like I'm probably missing something simple. Digital Ocena was unable to provide further support on this. I've worked with virtualenv for a long time and am familiar with what to do once I get it installed, I'm just stuck here as it's my first time setting up a Centos host. Can you tell what I'm missing?
Thank you!
Changing to root user did the trick. Thanks CasualDemon.
Nowadays, if you'd like to install setuptools & pip easily, you can run this file with your python interpreter:
get-pip.py
You made need administrator (root) privileges for installing it to your system python (e.g sudo python get-pip.py.
Afterwards you can upgrade pip and/or setuptools through e.g:
$ pip install -U setuptools
$ pip install -U pip
I recommend for most python development you only install setuptools, pip, and virtualenv as root (or purely virtualenv, if you're being conservative). After, you can use virtualenv virtual environments to create isolated python environments which don't need to install to the system python or affect its installed packages. That way no other python (and/or pip invocations) needs to be run as root.

Unable to install YAML for Python2.7 on my mac

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.

Categories