2
votes

On Ubuntu 16.04 I created an environment with this command: conda create -n ros2 python=2.7

And then activated it like so: conda activate ros2

But then python --version gives "Python 3.5.2"

Why is this so? How can I set the version of python to be 2.7?

which python gives "/home/brads/anaconda3/envs/ros2/bin/python"

echo $PATH gives: "/opt/ros/kinetic/bin:/home/brads/anaconda3/envs/ros2/bin:/home/brads/anaconda3/condabin:/home/brads/bin:/home/brads/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda/bin:/snap/bin"

Contents of /opt/ros/kinetic/bin:

binvox2bt                 edit_octree                     opencv_waldboost_detector  roslaunch-deps  rosservice   rqt_dep           stage
bt2vrml                   eval_octree_accuracy            rosbag                     roslaunch-logs  rossrv       rqt_graph         tf_remap
catkin_find               graph2tree                      rosboost-cfg               rosmake         rosstack     rqt_image_view    view_frames
catkin_init_workspace     log2graph                       rosclean                   rosmaster       rostest      rqt_logger_level  xacro
catkin_make               opencv_annotation               rosconsole                 rosmsg          rostopic     rqt_plot
catkin_make_isolated      opencv_createsamples            roscore                    rosmsg-proto    rosunit      rqt_shell
catkin_test_results       opencv_interactive-calibration  roscreate-pkg              rosnode         roswtf       run_selftest
catkin_topological_order  opencv_traincascade             rosgraph                   rospack         rqt          rviz
compare_octrees           opencv_version                  roslaunch                  rosparam        rqt_bag      selftest_example
convert_octree            opencv_visualisation            roslaunch-complete         rosrun          rqt_console  selftest_rostest

Output of which -a python :

/home/brads/anaconda3/envs/ros2/bin/python
/usr/bin/python

Output of python -c "import sys; print(sys.executable)": "/usr/bin/python3"

Output of env | grep "PYTHON"

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.5
PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages:/home/brads/anaconda3/envs/ros2/lib/python2.7/site-packages/
CONDA_PYTHON_EXE=/home/brads/anaconda3/bin/python
1
What OS are you on? What is the output of which python or where python (the former for Linux/macOS, the latter for Windows). If on Windows, are you using the Anaconda Prompt? If on Linux/macOS, what is the output of echo $PATH?darthbith
I edited the question to provide that informationbrad
This is very strange. Can you add which -a python and python -c "import sys; print(sys.executable)"?darthbith
Edited the question to add. I was using virtualenv briefly before I started using conda if that affected anythingbrad
Thank you merv and darthbith for your help. I took another look at removing VIRTUALENVWRAPPER_PYTHON all the way and that did the trickbrad

1 Answers

2
votes

The problem seemed to be virtualenv_wrapper which I had installed prior to conda. I removed via pip uninstall virtualenvwrapper I also removed references to it in ~/.profile and then relogged in