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

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.

Related

Permission error [Errno13]Permission denied while installing robotframework-SikuliLibrary

I have a Linux machine with Ubuntu rel 20.10, I'm using the robot framework with Eclipse. I have a problem with a Sikulilibrary
doesnt'work. I tried to pip install robotframework-SikuliLibrary,
But i have this error
> Exception : Initializing test library Sikulilibrary with no arguments
> failed:Permission error[Errno13]Permission denied
I tried to install Selenium library all is ok,do you have any questions about this issue?
Robotframework 3.2
Python 3.8.6
Thanks a lot
pip wants to install the package in your system, and you don't have the right to write here. But... Do NOT use sudo with pip. This will install system-wide and can break your installation or a package can overwrite this one.
Use virtualenv, or pipenv.
E.g. To use virtualenv:
cd your-project
python -mvenv .venv
source .venv/bin/activate
# and then
pip install XXX
You will need to call source .venv/bin/activate anytime you want to work and launch your project. The behavior is to change the installation path to a local path (and not your system).
Or, like said #BIOS in https://stackoverflow.com/a/66785567/1472048 comment, use your "home" installation with "--user" option to install in ~/.local/lib.
Make sure that you are adding the module in the correct Python installation (your Python 3.8 and not the system Python) and that you are installing in your home directory. This way no special permission will be needed.
pip3 install --user robotframework-SikuliLibrary
The above will install the package in the user site-packages directory of the current (running) Python. In my case it is ~/.local/lib/Python3.9/site-packages, which is already in my PATH. It should be the case for you too, so you should be good to go.
Otherwise, if you have problems like ModuleNotFoundError just find your site-packages directory with:
python3 -m site
You will have it under USER_SITE. Take note of it and add it to PATH following help from this question.
Otherwise, like #Metal3D said, you could use a virtual environment

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

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.

Upgrading pip You are using pip version 7.1.2 to version 8.1.2

Hi I am trying to upgrade my pip version to 8.1.2
this command does not work:
pip install --upgrade pip
And I also tried to get it directly from the github directory, like explained here https://github.com/pypa/pip/archive/8.1.1.zip but then i get the following error:
Checking .pth file support in /Library/Python/2.7/site-packages/
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: '/Library/Python/2.7/site-packages/test-easy-install-21442.pth'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Python/2.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.
I m working on a Mac btw
You can follow it up with:
pip install -U pip
sudo !!
This has the same effect as:
sudo pip install -U pip
Or even better, move away from OS X's Python install, and instead install Python / pip via Homebrew:
brew install python
brew install python3
Try to open command prompt as an administrator, then try upgrade it, should works.
Your problem is that your user doesn't have write privileges to the /Library/Python/2.7/site-packages directory. That is what it means by [Errno 13] Permission denied
Try running the command with sudo prefixing the original command. Sudo allows you to safely run programs as root. You will need to type your password at the prompt.

Proper permissions for python installation directory?

I'm trying to use a python app on a server for the first time. I started by adding setuptools as root:
[root#server mydirectory]# yum install python-setuptools
Cool. Then I try setup.py:
[user#server mydirectory]$ python 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/lib/python2.4/site-packages/test-easy-install-25752.write-test'
This directory /usr/lib/python2.4/site-packages is owned by root, so that makes sense.
My question is, should I chmod the site-packages directory, or should I be running setup.py as root?
The traditional way to install stuff system-wide as a non-root user is to use sudo. Which is why you see things like this all over the Python docs:
sudo python setup.py install
Some people prefer to instead make the site-packages group-writable by some "dev" group so you don't need to do this. (This is effectively what the Mac package manager Homebrew does.)
Alternatively, you can install into per-user site packages. Not every project can do this, but anything based on modern setuptools should be able to do so.
And, while we're at it, if you're installing stuff based on modern setuptools, it's probably better to pip install . instead of python setup.py install anyway. That will, among other benefits, create egg-info files so the package can be detected as a dependency, uninstalled, etc.
See the Python Packaging User Guide for more information.
Finally, you may want to consider using a virtual environment. With Python 3.3+, this is built in as venv, although it doesn't have its own pip until 3.4. With earlier versions of Python, you can install virtualenv off PyPI.
Many hosted server environments for Python (2.x or 3.x) come with virtualenv pre-installed. If not, installing it system-wide will of course require you to be root… but after that, you will be able to install (most) other packages into per-project virtual environments instead of system-wide.
Installing packages with pip/easy_install and running directly setup.py files require root privileges because they read/write in those restricted folders.
Usually hosts like www.openshift.com support a virtualenv for you so you just activate it and you have your own per-user environment. Affecting the global site-packages is usually forbidden since it may be a shared host.
In my experience, in a local ubuntu-installed laptop, I have two options:
Run installs as sudo
Run installs in a virtualenv
perhaps your host, if shared, supports virtualenv. Try asking them if it doesn't support it.

Categories