简体   繁体   中英

How to set path variable inside Spyder on Linux?

I am using a package that requires me to add the following line to my bashrc

export PATH=${PATH}:~/cozmo/plataform-tools

It works perfectly when I call python3 or ipython3 from the command line. However, when I start Spyder by double clicking a python file in Nautilus, it cannot find and execute a required file that is inside that folder. So, my question is

How to make the spyder console to use the PATH set at my bashr? Or how to set the path inside spyder?

I am aware of Why do the environment variables set in command prompt have no effect when I start Spyder , but it don't solve my problem, since I need to call it from Nautilus (and not use sudo) and I do not want to add a line declaring the path in all my programs.

( Spyder maintainer here ) For Spyder to take notice of any environment variable set in your .bashrc , you need to start it from a terminal.

This is because Spyder doesn't have the ability to read environment variables when started in a graphical way.

I found a solution to setting a variable in ipython console. Just include

import os, os.environ['PATH']+=':/home/bernardo/cozmo/platform-tools

in Tools → Preference → iPython console → Startup → Lines. I believe a similar solution can be applied if Python console is being used instead of iPython console.

By doing this I am able to use the package that requires this path even when spyder is not started from the terminal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM