1

  In my Ubuntu16.04, there are python 2 and python 3 default. In addition, i have installed anaconda too. I am sucked by the 'python' cmd. Every time i use pip or pip3 install, I don't know where the package install, python2 or python 3? And I use conda install to install anaconda package. I also use anaconda env to manage different virtual env. But I think it mix with my local Python 2 and 3.

  For example, in directory /usr/bin, I found many soft links like this: enter image description here

   When i try 'python' cmd, it just confuse me! enter image description here

   Why python3m are local, shouldn't it be anaconda? Why python3 are anaconda, shouldn't it be local? Then I found that if I use ./python2 or ./python3, I found it is correct now! enter image description here

  So I know it is caused by environment variables. I echo $PATH, Found it like this: /home/kinny/.pyenv/shims:/home/kinny/.pyenv/bin:/home/kinny/anaconda3/bin:/home/kinny/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/ant/bin:/snap/bin:/opt/maven/bin:/usr/lib/jvm/java-8-oracle/bin

   I have used update-alternative --config python to configure default python, but it doesn't work! It sames mixed with each others. enter image description here

   Now I just want to install tensorflow 0.11 in local python3, because in anaconda it is 0.10 version by default. So how can I change this. I just want to use python python3 and python3m represents python2.7 python3.5 and anaconda python respectively, How can I do that! use pip and pip3 for local python2 and python3 respectively!

2
  • 1
    You can create virtual environments for different python versions. Not sure from your description if that's what you are doing here?
    – Marcin
    Commented Nov 1, 2016 at 4:24
  • 1
    I'd say this is the cleanest way without having to remember anything. Create a virtual environment in the folders that you're going to code. Use the specific interpreter (find it using which python and which python3 in the cmd) that you want while creating it. Activate that environment and install packages in it. Use that environment whenever you're working on that project. Commented Nov 1, 2016 at 5:09

3 Answers 3

0

I ran into a similiar problem when setting up PyCharm Edu to work with Anaconda. I found that I had several versions of Python installed and it was very hard to keep track of which version the IDE was referencing. My CS professor gave me the advice of simply removing the versions of Python I didn't frequent. I now just have Anaconda installed; and use the Anaconda Prompt as my Python console. I also rely on PyCharm's IPython for the developer console. However, if you still want differing versions of Python installed (say your doing QA testing for older devices); there is the really helpful command: which python. When entered into the python console or Anaconda Prompt: which python will display the directory associated with the currently executing Python Shell. This enables you to better keep track of to what particular python.exe the current window is referring to.

0

Follow up to the comments mentioning using virtualenv and virtualenvwrapper.

Here are the official docs and a good blog post to follow for getting started using virtualenv's is here:

https://virtualenv.pypa.io/en/stable/installation/

http://virtualenvwrapper.readthedocs.io/en/latest/install.html

http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/

Also, once you are setup you can create virtualenv's specifying which python installation you want to use.

which python3

returns

/usr/bin/python3

Then create a virtualenv with that python path. Where example_env is the name of the virtualenv.

mkvirtualenv -p /usr/bin/python3 example_env

Then activate the virtualenv using virtualenvwrapper.

workon example_env

Finally, install tensorflow and other dependencies with pip.

pip install tensorflow
0

the which command is very useful for finding the path to the executable that is first in your path. Zsh also has the where command, which will show you all instances of the given executable that show up in your path. For managing different python versions, you have a lot of options. The easiest for most people tends to be anaconda, using conda environments. The installer will ask you to add some stuff to your .bashrc file, which will then make anaconda's binaries come first in your path. Anything else you run after the .bashrc gets sourced after that, will then use that first, including PyCharm. For graphical desktop apps to pick up the change, you may need to log out and back in again. If you only need one version each of python 2 and python 3, you can just use the ones available via apt. Depending on your Ubuntu version, Python 2 is definitely installed by default as it is used by many system utilities, including apt itself. Some newer versions may also install python 3 by default, but I do not remember for sure. Another option is to install the versions of python you need in an alternate location, such as /opt/python/<version> and then using environment-modules (installed via apt install environment-modules) or Lmod to control which versions are being used, but that may or may not be easy/convenient to use with a desktop application such as PyCharm.

for TensorFlow, 1.11 is available in anaconda, but I don't remember if it's in the default channel or not.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.