2

I want to launch Spyder with tensorflow environment activated directly through a desktop icon. For this purpose, I created a desktop icon launching a virtualenv and then my application. Many posts already exist but I cannot find a solution for this exact problem. Here is my spyder.sh file:

#!/bin/bash
source /home/alexis/tensorflow/bin/activate
spyder3

and here is my desktop entry:

[Desktop Entry]
Version=1.0
Name=Spyder     
Comment=Spyder
Exec='/home/alexis/Launcher/spyder.sh'
Icon=spyder3
Terminal=true
Type=Application
Categories=Application;
Name[en_US]=Spyder

The files have chmod +x. From a terminal, the script works as expected. From the desktop, the script launches Spyder but the environment is not activated. What I am missing?

Related questions not answering my question: How do I make a desktop icon to launch a program? and How do I automate the activation of Python environment

ahstat
  • 121

2 Answers2

3

To run your python script within the virtual environment, you simply have to execute the python binary which is in the bin folder of your virtual env folder.

Ie : if your virtual env within /home/alexis/myvirtualenv and if the script you want to execute is named /home/alexis/scripts/my_python_file.py, you will have to run your python script this way :

/home/alexis/myvirtualenv/bin/python /home/alexis/scripts/my_python_file.py

For your specific needs : Try to put the following code within spyder.sh :

#!/bin/bash
/home/alexis/tensorflow/bin/python spyder3  # you may have to put the full path to spyder3
rebrec
  • 350
0

I had a similar issue before. The difference lays between an interactive shell and a non-interactive shell. so change #!/bin/bash for #!/bin/bash -i and it should work ;)