Skip to content
This repository was archived by the owner on Dec 6, 2021. It is now read-only.

Commit 758f165

Browse files
committed
Share ROS setup with bash script.
1 parent cdeaf82 commit 758f165

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

doc/linux_ros_anaconda_warning.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,46 @@ $ source activate RoboND
3030
```
3131
And it should work! But in this case, you'll need to remember to do this each time you want to use your Anaconda Python install.
3232

33-
For a more permanent solution, you can add the `unset PYTHONPATH` line to your `.bashrc` file, but you need to make sure you drop it into the right location, after sourcing ROS. To do this, open your `.bashrc` file (should be located in your `~/` directory) and find the line that says `source /opt/ros/kinetic/setup.bash` and make this edit:
33+
## Recommended ROS Approach
3434

35-
```
36-
source /opt/ros/kinetic/setup.bash
37-
unset PYTHONPATH
35+
For a more permanent solution:
36+
37+
1. Install anaconda and choose not to add it to your path
38+
2. Create a script named: ~/bin/cenv, with the following contents:
39+
```
40+
#!/bin/bash
41+
unset PYTHONPATH
42+
export PATH=$HOME/anaconda3/bin:$PATH
43+
source activate $1
44+
```
45+
3. Login out and log back in to trigger the ~/bin path to be automatically added to your PATH variable.
46+
Then you can run:
47+
```
48+
. cenv RoboND
49+
```
50+
anywhere on your system and it just works.
51+
52+
### Example
53+
54+
**Note "." is the same as "source" and is easier to type**
55+
56+
```sh
57+
$ . /opt/ros/kinetic/setup.bash
58+
$ which python
59+
/usr/bin/python
60+
$ echo $PYTHONPATH
61+
/opt/ros/kinetic/lib/python2.7/dist-packages
62+
$ . cenv RoboND
63+
(RoboND) $ which python
64+
~/anaconda3/envs/RoboND/bin/python
65+
(RoboND) $ echo $PYTHONPATH
66+
67+
(RoboND) $ ipython
68+
Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33)
69+
Type 'copyright', 'credits' or 'license' for more information
70+
IPython 6.0.0 -- An enhanced Interactive Python. Type '?' for help.
71+
72+
In [1]: import cv2
3873
```
3974

40-
See [this post](https://stackoverflow.com/questions/43019951/after-install-ros-kinetic-cannot-import-opencv) and [this post](https://stackoverflow.com/questions/17386880/does-anaconda-create-a-separate-pythonpath-variable-for-each-new-environment) for more information on the matter.
75+
See [this post](https://stackoverflow.com/questions/43019951/after-install-ros-kinetic-cannot-import-opencv) and [this post](https://stackoverflow.com/questions/17386880/does-anaconda-create-a-separate-pythonpath-variable-for-each-new-environment) for more information on the matter.

0 commit comments

Comments
 (0)