1

I am setting-up a ubuntu 15.10 vm (win7 virtualbox host) and want to use python for some machine learning experiments using python (i will need numpy, scipy, sklearn, matplotlib, xgboost).

As i know from past experience that dependencies can be tricky and that those lirabries don't always install straightaway, i would like to use virtualenv.

Virtualenv installation doc recommends using pip to install packages, ok but now when i list the python versions available on my box, i find 5 of them (in case you wonder, this comes from a vanilla 15.10 installation...):

hippo@u64-ml:~$ sudo find / -type f -executable -iname 'python*' -exec file -i '{}' \; | awk -F: '/x-executable; charset=binary/ {print $1}' 
/usr/bin/python3.4
/usr/bin/python3.4m
/usr/bin/python2.7
/usr/bin/python3.5m
/usr/bin/python3.5

So now i am unsure of:

1/ how to make sure that the virtualenvs i create are for a given python version?

2/ how do i install packages for say python3.5? if i use pip3 i don't know where it will put its binaries and how python will find them (is it for python3.4, 3.4m, 3.5, 3.5m?).

EDIT with results from answer below:

hippo@u64-ml:~$ virtualenv -p python3.5 hippo3.5
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in hippo3.5/bin/python3.5
Also creating executable in hippo3.5/bin/python
Installing setuptools, pip...done.   ## installs the right pip
hippo@u64-ml:~$ which pip            
hippo@u64-ml:~$ source hippo3.5/bin/activate   ## now when i activate the env, all works perfect!!
(hippo3.5)hippo@u64-ml:~$ which pip
/home/hippo/hippo3.5/bin/pip
(hippo3.5)hippo@u64-ml:~$ which python
/home/hippo/hippo3.5/bin/python
3
  • 1
    You actually have three versions, also which -a python which -a python3 will show you them all Commented Mar 23, 2016 at 22:59
  • 1
    This guide should tell you all you need to know about using a virtaulenv docs.python-guide.org/en/latest/dev/virtualenvs Commented Mar 23, 2016 at 23:05
  • 1
    thanks for the guide, it's better than the page i was using so far Commented Mar 23, 2016 at 23:29

1 Answer 1

3

Assuming you installed virtualenv (sudo apt-get install python-virtualenv), you would use it to create an env with the Python binary of your choosing. pip is installed in new virtualenvs, so you would activate the env and use it to install packages.

virtualenv -p python3.5 env
source env/bin/activate
pip install flask
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.