Skip to content

Instantly share code, notes, and snippets.

@vr2262
Last active October 5, 2015 15:34
Show Gist options
  • Save vr2262/f0cebd8cab3ffb5bcd0c to your computer and use it in GitHub Desktop.
Save vr2262/f0cebd8cab3ffb5bcd0c to your computer and use it in GitHub Desktop.
Python 3 development environment

##Instructions

  1. Install the dependencies from the top of this page: https://github.com/yyuu/pyenv/wiki/Common-build-problems
  2. $ git clone git://github.com/yyuu/pyenv.git ~/.pyenv

pyenv allows you to manage Python (and pip, etc) versions easily. 3. $ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc (Assuming you're using bash) 4. $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc 5. $ source ~/.bashrc 6. To install a particular version of Python to your machine:

$ pyenv install 3.4.2 (for example)

$ pyenv rehash - this make the new version visible to pyenv 7. To choose the version of Python you want to use, follow this guide: https://github.com/yyuu/pyenv#choosing-the-python-version

Long story short, $ pyenv global $VERSION sets the Python version you use across the board, while $ pyenv local $VERSION sets the Python version for the current directory and its subdirectories. Once you've done that, $ python --version should display the version you chose. 8. $ sudo pip install virtualenv virtualenvwrapper 9. $ echo 'export WORKON_HOME=$HOME/.virtualenvs' >> ~/.bashrc 10. $ echo 'source /usr/bin/virtualenvwrapper.sh' >> ~/.bashrc You might run into some trouble with this line (I did at some point). If you do, try to find another file on your computer called virtualenvwrapper.sh and point to that instead. 11. $source ~/.bashrc 12. To create a virtual environment:

$ mkvirtualenv virtual_environment_name

If you want to use a specific version of python in your virtual environment:

$ mkvirtualenv virtual_environment_name --python=/path/to/python 13. Now you can enter this virtual environment with $ workon virtual_environment_name (tab autocompletion works!), exit it with $ deactivate, or delete it with $ rmvirtualenv virtual_environment_name. 14. Within your virtual environment, you can use pip to install whatever you need. Try $ pip install ipython - you should be able to get IPython to work with your virtual environment without much fuss.

Mostly taken from my own experience and this post: http://unix.stackexchange.com/a/83721

Alternative (Arch Linux)

You can install pyenv and virtualenvwrapper from the Arch repositories to avoid messing with your .bashrc or sudo pip.

Alternative

If you feel like building Python 3 from source (thanks Denis):

  1. Download whichever version of Python you want (e.g., https://www.python.org/downloads/release/python-342/)
  2. $ ./configure --prefix=/opt/python3
  3. $ make && sudo make install
  4. The resulting /opt/python3/bin/ folder contains the python3 interpreter, pip3, and pyvenv3.
@vr2262
Copy link
Author

vr2262 commented Oct 10, 2014

No, the instructions are not convenient. The resulting environment is convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment