Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install python for one user on centos?

Tags:

python

centos

I'm working a linux machine running CentOS. I don't have full sudo powers and theres multiple versions of python already installed on the machine and the whole thing is a bit of a mess, stuff like numpy doesn't work and I need to install modules which rely on that.

I was wondering if its possible to just install python (and hopefully R) into my own home directory or something and then install the modules I need into that directory and run what I need from there?

Thanks

like image 863
TheFoxx Avatar asked Oct 21 '25 06:10

TheFoxx


2 Answers

Try using virtualenv. Of course this assumes that your system already has virtualenv installed.

https://pypi.python.org/pypi/virtualenv

Basic usage:

virtualenv venv

That creates a directory called 'venv' at your current folder. It puts in the appropriate python and pip binaries.

To go into the virtual environment:

. venv/bin/activate

or equivalently:

source venv/bin/activate

That is the key step. From then on, any packages installed using pip will be local to the virtualenv folder that we created above. Remember to do the above step before installing your packages and running your programs. Running python will also use the python from the virtualenv.

You should see something like:

(venv)[username@host]$

on your shell.

Install packages using pip like this:

pip install packagename

This will install packages for the virtualenv we created in the first step.

pip makes use of a requirements.txt file for specifying packages required for your python programs. If you have a requirements.txt file, you can use:

pip install -r requirements.txt

to install the packages specified in that file.

For running your python program:

python programName

or use the relevant command you need. Based on my limited experience so far, I have run gunicorn for web applications. This will use the python and associated libraries from our virtualenv.

To deactivate the virtualenv, use:

deactivate

Hope that helps!

like image 185
yanhan Avatar answered Oct 22 '25 18:10

yanhan


Make a directory where you install your own software:

mkdir -p ~/sw/src
cd ~/sw/src

Download and untar Python source into this directory. Configure it to install into ~/sw, then compile (make sure all the required headers are available, notably those for SSL if you want to open HTTPS urls with urllib2):

./configure --prefix=$HOME/sw
make
make install

Finally, set your PATH to include $HOME/sw/bin in .bashrc (or a similar shell startup file). Now run python.

R should work similarly.

like image 23
Fred Foo Avatar answered Oct 22 '25 20:10

Fred Foo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!