在spyder中使用系统环境变量 [英] Using system environment variables in spyder

查看:90
本文介绍了在spyder中使用系统环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Python 2 编码的程序需要运行,我想通过 anaconda 软件在 spyder 中运行它.问题是要通过终端运行程序,我之前必须在系统环境变量中添加两个新变量:1)计算机中的一个文件夹,其中一些必需的包2) 带有所需许可证的 IP 地址的变量.

I have a program coded in Python 2 that I need to run and I would like to run it in spyder via anaconda software. The issue is that to run the program via the terminal I had to previously add in my system environment variables two new variables: 1) one folder in the computer where some required packages are 2) a variable with the ip address for the required license.

尽管我定义了这些变量并且程序在终端中运行没有问题.当我在 spyder 中运行它时出现错误,因为它没有使用这些变量.

Although I have these variables define and the program runs without issues in the terminal. When I run it in spyder there is an error because it is not using those variables.

我该如何解决这个问题?我负责一些关于 anaconda 创建的虚拟环境,该环境未加载这些变量,但我无法理解其他任何内容.例如,如果我在 anaconda 之外使用 pycharm,它也可以完美运行

How can I fix this? I head something about anaconda creates virtual environments that is not loading those variables but I could not understand anything else. For example if I use pycharm, outside anaconda, it also works flawlessly

谢谢!伊曼纽尔

推荐答案

我相信 Anaconda 提供了有关设置环境变量的说明,但这种方法似乎很复杂.

I believe Anaconda offers instructions on setting environment variables but that approach seemed complicated.

设置环境变量似乎不再是 Spyder 中的一个选项.

Setting an environment variable no longer seems to be an option in Spyder.

作为一种解决方法,Spyder 确实允许您指定一个启动文件:首选项 ->IPython 控制台 ->启动

As a workaround Spyder does allow you to specify a startup file: Preferences -> IPython Console -> Startup

在启动文件中,您只需运行以下内容:

In the startup file you just run something like:

import os
os.environ['my_var'] = 'my_value'
os.environ['test'] = 'test_value'

每次你启动一个新的 ipython 控制台时,这段代码都会运行.

Every time you start a new ipython console this code will run.

这篇关于在spyder中使用系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆