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

2 Answers 2

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
7
  • 1
    The code is working in a terminal (launching Spyder and access to tensorflow), but not through the desktop icon (launching Spyder but not in my virtualenv). I've replaced spyder3 with /usr/bin/spyder3
    – ahstat
    Mar 24, 2018 at 2:28
  • When the second line is only "/home/alexis/tensorflow/bin/python3", the problem is similar: OK in a terminal (open python3 in virtualenv), but not through desktop icon (open python3 but not in my virtualenv)
    – ahstat
    Mar 24, 2018 at 2:30
  • I have "There was an error launching the application." I tried with ", ' and with nothing. If I let Exec="xterm", it works but it is only an xterm
    – ahstat
    Mar 24, 2018 at 11:10
  • i made a mistake. Try Exec="xterm -e /home/alexis/Launcher/spyder.sh"
    – rebrec
    Mar 24, 2018 at 16:24
  • 1
    same error "There was an error launching the application."
    – ahstat
    Mar 25, 2018 at 8:25
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 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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