Can't install python egg due to directory permissions - python

I'm still getting familiar with python and python eggs so sorry if this is a stupid question. I want to know why easy_install appears to install the egg for the whole server to use rather than just locally for the account that tried to install it.
I created a simple helloworld module/egg and tried to install it on a server I have an account on. However, the account doesn't have root access (it's a tester's account). I get a "Permission denied" error message when installing it. When installing the module, it is trying to install to /usr/local/lib/python2.7/site_packages/blah/blah/blah. It's pretty clear it's b/c I don't have root access to write to this location.
easy_install hello-1.0-py2.7.egg
On my laptop (my account has root access), I can run the cmd above and see the module is installed by running 'pip freeze'. The slight difference is that Anaconda is running/installed on my laptop and seemed to be doing the package management for me.
So back to my original question; how does easy_install install eggs that we create ourselves? I was hoping/assuming it would install the module in my tester's account and not to /usr/local/lib/blha/blah/blah for all users to use/access. Is this an incorrect assumption? If this is incorrect thinking, how would someone install a module/egg where the account doesn't have root access? Thanks.

Se per easy_install or pip as a limited user? you'll want to use the --prefix option to easy_install and/or -d or -s.
I believe you could do something as simple as:
easy_install --prefix=$HOME hello-1.0-py2.7.egg

An option is to use virtualenv which allows you to create multiple virtual environments for Python, each with its own set of libraries.
Just create a virtualenv and then you can then install your module within it without requiring write access to the system Python installation.
There is a tutorial here: http://simononsoftware.com/virtualenv-tutorial/, but simply install virtualenv then:
$ cd $HOME
$ virtualenv test
$ cd test
$ source bin/activate
$ easy_install /path/to/hello-1.0-py2.7.egg
The package should be installed into ~/test/lib/python2.7/site-packages

Related

Cannot Use Pip Within Venv

I'm aware there are many similar questions but I have been through them all to no avail.
On Ubuntu 18.04, I have Python 2 and Python 3.6. I create a venv using the command below and attempt to install a package using pip. However, it attempts to install on the global system and not in the venv.
python3 -m venv v1
When I run 'which python' it correctly picks the python within the venv. I have checked he v1/bin folder and pip is installed. The path within the pip script is correctly pointed to toward python in the venv.
I have tried reinstalling python3 and venv, destroying and recreating the virtual environment and many other things. Wondering is there some rational way to understand and solve this.
The problem in my case was that the mounted drive I was working on was not mounted as executable. So pip couldn't be executed from within the venv on the mount.
This was confirmed because I was able to get a pip install using 'python -m pip install numpy' but when importing libraries, e.g. 'import numpy', was then faced with further error of:
multiarray_umath.cpython-36m-x86_64-linux-gnu.so: failed to map segment from shared object
which led back to the permissions issue as per github issue below. Fix for that by dvdabelle in comments then fixes dependent and original issue.
https://github.com/numpy/numpy/issues/15102
In his case, he could just switch drive. I have to use this drive. So the fix was to unmount my /data disk where I was working and remount it with exec option!
sudo umount /data
sudo mount -o exec /dev/sda4 /data
'which pip' now points to the pip in the venv correctly
Note: to make it permanent add the exec switch to the line for the drive in fstab as per https://download.tuxfamily.org/linuxvillage/Informatique/Fstab/fstab.html (make exec the last parameter in the options or user will override it) E.g.
UUID=1332d6c6-da31-4b0a-ac48-a87a39af7fec /data auto rw,user,auto,exec 0 0

Install python module only on home folder in server

I'm developing my master thesis on a university's server, so I have my account and I can log in and do all the stuff I want if I remain inside /home/myname/.
I'm developing some python scripts and now I want to integrate python with the octave module, which is not currently installed on the system, and , of course, I cannot do anything with sudo apt-get install .
How can I overcome this problem without asking to my teacher?
thank you all,
Fabio
Please don't copy python and pip. You should use a virtualenv to install project-specific packages. This is particularly useful in your use-case where you can't install things at the system level. Even if you could, virtualenvs are recommended so the dependencies of each project are isolated.
Here is a quick primer that should get you going.
Create the virtualenv
virtualenv ~/project/env
Activate the virtualenv
source ~/project/env/bin/activate
This will modify your bash prompt by placing the name of your virtualenv in parenthesis to indicate that your virtualenv is activated.
(env) hostname:current_folder user$
Install Packages into the virtualenv
pip install -r requirements.txt
Use the virtualenv
python script.py
Use virtualenv by default in a script
script.py
#!~/project/env/bin/python
print('hello world!')
Then from the command line
chmod ugo+x script.py
./script.py
hello world!
Deactivate the virtualenv
deactivate
Make yourself a local copy of python and pip, then you can install whatever modules you want and not have to worry about getting a sysadmin to help you.
There are some good instructions here
Go here to get the link to the version of python you need and substitute it in the instructions above.
In your .bashrc add alias and path to your local copy - you may need to modify this for your own situation:
alias python="~/bin/python"
PATH=~/.local/bin:~/bin:$PATH
For the PATH - when you install local copies of modules through pip they by default go to ~/.local - change this if you prefer.
Begin your scripts with:
#/usr/bin/env python
so they use your preferred python version

Python pip: install in specific non-user directory and ignore system wide packages

I want to set up a Python environment for a whole team and I don't have root access to the server.
I have done a similar thing with Perl and expected to be able to do this for Python in a similar way but I keep running into a problem.
Basically, I want to be able to install a package into /SOME/DIR on the system while ignoring any system wide versions of that package.
However, when I run
pip install --install-option="--prefix=/SOME/DIR/" --up --ignore-installed SOME-MODULE
I keep getting a "permission denied" error because pip keeps trying to remove system-wide packages when upgrading.
What does work is this
pip install --user --up --ignore-installed SOME-MODULE
Which does not try to touch the system-wide packages but it installs the module into a directory in $HOME/.lib, which is not what I need.
It seems impossible to combine --user and a "--prefix" option, so it sems that I can either install into an arbitrary path but then get conflicts with already install system-wide packages or install into my home directory. Neither of them are what I need.
For now I have been using the --user option and then moved the installed files across to /SOME/DIR which works but seems odd.
Am I missing something? I have read up on virtualenv but this also doesn't quite sound like what I need. Thanks for your help!
Note that --install-options is passed directly to the packages setup.py install command - this requires the installation directory to be in your python path.
add it to your PYTHONPATH i.e.
set -gx PYTHONPATH $PYTHONPATH '/home/user/temp/lib/python3.4/site-packages'
and run pip
pip install django==1.6 --ignore-installed --install-options="--prefix=/home/user/temp"
Mostly this is a pain in the ass if you have to do this for each library (note that you will still have potential conflicts with imports if you want to use certain standard libraries from the default site-packages dir, and others from your custom dir). And the best choice is probably, as the comment says, to install virtualenv and virtualenvwrapper
I had a similar problem (permission denied + no root access), --build option made it work: pip install --install-option="--prefix=/path/to/local/lib" --build=/tmp wget

install a library for python

i'm trying to install a library for python of gene ontology programming [GOGrapher]. In the page they told me this:
$ `svn co https://projects.dbbe.musc.edu/public/GOGrapher/trunk GOGrapher`
$ cd GOGrapher
$ su -
# python setup.py install
I do everything, but in the last step a get an error
error: /usr/local/lib/python2.7/dist-packages/GOGrapher-0.0.egg-info: Permission denied
What is wrong? I'm new on this, but I do what I can.
Try
sudo python setup.py install
instead. (Works for me on Mac OS 10.7.3, while the suggested su - solution doesn't).
It is not a good idea to install things as superuser in the filesystem. In Python you can always install libraries locally.
Assuming you are already in GOGrapher directory:
$ python setup.py install --home
should install the library in your home directory. Later, you have to add the library PATH to the PYTHONPATH environment variable, so Python will know where to search for it.
$ export PYTHONPATH=$HOME/lib/python
The directory might be slightly different (lib/python2.7 or even lib/python2.7/site-packages), you can check it, tough.
To make it permanent, you should add it in your .profile, .bashrc, or whatever is the shell you are using.

beginner installing nosetests package

I'm trying to install the following as per the learnpythonthehardway tutorial:
pip from http://pypi.python.org/pypi/pip
distribute from http://pypi.python.org/pypi/distribute
nose from http://pypi.python.org/pypi/nose/
virtualenv from http://pypi.python.org/pypi/virtualenv
I've visited these links and clicked the download button; each file is in my downloads folder now, and I unarchive/unzipped them- not sure what this means but it seemed required. Are they "installed"? If not, what does it mean to really install them? I've tried typing nosetests in the terminal (as the book says you should), as well as tried easy_install but that doesn't seem to work. It appears my understanding is limited in a number of ways here.
I get the following -bash: nosetests: command not found, but am trying to get:
nosetests . ---------------------------------------------------------------------- Ran 1 test in 0.007s
OK
This works on mac, it may work on linux
1)Open terminal (Be prepared to enter your password)
2)Type: sudo easy_install pip
3)Type: sudo pip install distribute
4)Type: sudo pip install nose
5)Type: sudo pip install virtualenv
Hope that helps, cheers!
They are not yet installed.
Each has its own vagaries about how exactly the install process works and in fact some of those packages will include the other packages with them. I.e.
"If you use virtualenv, a copy of pip will be automatically be
installed in each virtual environment you create."
http://pypi.python.org/pypi/pip
As a relatively new python user myself, (and having gone thru a similar process not long ago) I am eagerly awaiting the more complete answers that come back for this one.
Find out where the nosetests script is. On OSX:
/usr/local/share/nosetests
Execute directly, or set up a bash alias, perhaps in .bash_profile:
alias nosetests='/usr/local/share/python/nosetests'
alias nosetests3='/usr/local/share/python3/nosetests'
You were on the right track, but the package is actually called "nose". The documentation for nose (nosetests is the script) can be found here:
https://nose.readthedocs.org/en/latest/
The short answer is that you have 2 basic options: easy_install or pip. Install using setuptools/distribute: easy_install nose. Install using pip: pip install nose
Install Python 2.7 and after just do this (only on Windows - Windows PowerShell):
Setup PATH env:
C:\Python27\;C:\Python27\Scripts\", "User"
pip is already installed
3.
.\pip install distribute
4.
.\pip install nose
5.
.\pip install virtualenv

Categories

Resources