https://github.com/phdenzel/local-python-install
How to install python on a server without sudo rights
https://github.com/phdenzel/local-python-install
how-to tutorial
Last synced: about 1 month ago
JSON representation
How to install python on a server without sudo rights
- Host: GitHub
- URL: https://github.com/phdenzel/local-python-install
- Owner: phdenzel
- Created: 2017-06-19T09:27:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-04T13:36:19.000Z (almost 7 years ago)
- Last Synced: 2025-02-26T06:34:58.337Z (about 1 year ago)
- Topics: how-to, tutorial
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
#+TITLE: How to locally install python
#+AUTHOR: phdenzel
On a server or shared machine, you might want to install stuff locally, i.e. in your home directory.
I often get asked how I installed python this way.
This is what I did (more or less):
*** Installing in ~/local/python
First, we need to create the directories, where python has to be installed.
#+BEGIN_SRC shell
mkdir -p ~/local/python/2.7
#+END_SRC
Then go to the created directories and download the python source code
(I used 2.7.something, however if you're starting out completely new, I recommend 3.6.5).
#+BEGIN_SRC shell
cd ~/local/python
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
#+END_SRC
Unpack it... do you remember the tar flags?
#+BEGIN_SRC shell
tar zxfv Python-2.7.15.tgz
#+END_SRC
Make the directories safe from outside influence
#+BEGIN_SRC shell
find ~/local/python -type d | xargs chmod 0755
#+END_SRC
... and finally install in your local directory with
#+BEGIN_SRC shell
cd Python-2.7.15
./configure --prefix=$HOME/local/python/2.7
make && make install
#+END_SRC
Make sure to include the ~--prefix~ flag, since this is where the output of ~make~ is installed.
On UNIX machines this is by default in ~/usr/local~.
If you've received an error message about the C compiler, you might have to change the second line to
#+BEGIN_SRC shell
CC=gcc ./configure --prefix=$HOME/local/python/2.7
#+END_SRC
or a similar compiler of your choice (that works).
On macOS (if you decide to install ~python~ from source code) many dependencies are very outdated!
That's why if you installed another Tcl/Tk version (~8.6~) for example you can specify additional flags
#+BEGIN_SRC shell
./configure --prefix=$HOME/local/python/2.7 \
--with-tcltk-includes='-I/Library/Frameworks/Tcl.framework/Headers -I/Library/Frameworks/Tk.framework/Headers' \
--with-tcltk-libs='/Library/Frameworks/Tcl.framework/Versions/8.6/Tcl /Library/Frameworks/Tk.framework/Versions/8.6/Tk'
make && make install
#+END_SRC
If you want to build a framework-based python on macOS use
#+BEGIN_SRC shell
./configure --prefix=$HOME/local/python/2.7 \
--enable-framework=$HOME/local/python/2.7 \
--with-tcltk-includes='-I/Library/Frameworks/Tcl.framework/Headers -I/Library/Frameworks/Tk.framework/Headers' \
--with-tcltk-libs='/Library/Frameworks/Tcl.framework/Versions/8.6/Tcl /Library/Frameworks/Tk.framework/Versions/8.6/Tk'
make && make install
#+END_SRC
On linux, Tcl can easily be installed with ~sudo apt-get install tcl8.6 tcl8.6-dev libtcl8.6 tk8.6 tk8.6-dev libtk8.6~.
The additional flags then are
#+BEGIN_SRC shell
./configure --prefix=$HOME/local/python/2.7 \
--with-tcltk-includes='-I/usr/include/tcl8.6 -I/usr/include/tk8.6' \
--with-tcltk-libs='/usr/lib/*-linux-gnu/libtcl8.6.so /usr/lib/*-linux-gnu/libtk8.6.so'
make && make install
#+END_SRC
On some linux machines, it can happen that ~lib-dynload~ is installed in a non-default location.
To easily fix this, I found that the following command usually helps
#+BEGIN_SRC shell
cp -r $HOME/local/python/2.7/lib64/python2.7/lib-dynload $HOME/local/python/2.7/lib/python2.7/
#+END_SRC
*** Defining path variables
Now that we have locally installed python, we have to define the path to the local library in our ~.bash_profile~.
#+BEGIN_SRC shell
export PATH=$HOME/local/python/2.7/bin:$PATH
export PYTHONPATH=$HOME/local/python/2.7
#+END_SRC
To test if it worked type
#+BEGIN_SRC shell
source ~/.bash_profile
which python
#+END_SRC
or something similar (like ~.bashrc~).
If the output of ~which~ includes ~/local/python/~ it worked!
*** Setting up pip
I use pip to install all my python libraries.
Since python is already installed, it is relatively painless to install ~pip~.
#+BEGIN_SRC shell :export
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python - --user
#+END_SRC
This downloads and installs ~pip~ locally in ~$HOME/.local/bin~.
If you installed python as a framework, the above ~pip~ install command will automatically
install ~pip~ in ~$HOME/Library/Python/2.7/~.
However, if you want to install it still in ~$HOME/.local/~ use
#+BEGIN_SRC shell :export
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python - --prefix=$HOME/.local/
#+END_SRC
Now, we just have to update the PATH in your ~.bash_profile~ and you're good to go...
#+BEGIN_SRC shell
export PATH=$HOME/.local/bin:$PATH
#+END_SRC
Again, test it with
#+BEGIN_SRC shell
source ~/.bash_profile
which pip
#+END_SRC