Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
678 Views

Python can't find caffe when started with "docker exec"

I have a running container with python and pycaffe in it. If I use docker exec to enter via a bash, I can the run a python script that imports the caffe module. But it fails when using this command:

 

docker exec -ti dts bash -c "python /root/init_random_weights.py"

 

mroos@synapse:scratch$ docker exec -ti dts bash -c "python /root/init_random_weights.py" Hello Traceback (most recent call last): File "/root/init_random_weights.py", line 4, in <module> import caffe ImportError: No module named caffe

 

Why isn't python finding caffe when called in this manner? My .bashrc on the running container adds caffe to PYTHONPATH:

 

export PYTHONPATH=/usr/local/caffe/python:

 

What am I misunderstanding here?

0 Kudos
2 Replies
idata
Community Manager
242 Views

Thanks to some info here: https://docs.docker.com/engine/reference/commandline/exec/, I implemented a workaround by defining the PYTHONPATH env variable in the docker exec call as such:

 

docker exec -ti -w /root -e PYTHONPATH=/usr/local/caffe/python: dts bash -c "python /root/init_random_weights.py"

 

But I still don't understand why, in the absence of the -e option, the PYTHONPATH of my host machine is used rather than the PYTHONPATH of the .bashrc file in the container.

idata
Community Manager
242 Views

@mattroos How did you build your docker container/image? There are some instructions for NCSDK 2 at https://movidius.github.io/ncsdk/docker.html.

Reply