如何在pycharm中获取额外的环境? [英] How to source additional environment in pycharm?

查看:47
本文介绍了如何在pycharm中获取额外的环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ROS 应用程序,它有一个带有 setup.bash 文件的工作空间和另一个带有自己的虚拟环境的 python 脚本.

I have a ROS application which has a work space with a setup.bash file and another python script with its own virtual environment.

到目前为止,这是我在终端中所做的:

So far this is what I do in my terminal:

1_ pipenv shell (to activate my python virtual environment).
2_ source ../ros_workspace/devel/setup.bash
3_ python some_python_script.py

此代码按我的预期工作.

This code works as I expect.

但是,我想做同样的事情并在 pycharm 中运行此脚本,其中我的虚拟环境已被激活.但是我如何额外获取设置 bash?我的 setup.bash 文件也如下所示:

However, I want to do the same and run this script in pycharm, where my virtual environment is already activated. But how do I source the setup bash additionaly? My setup.bash file also looks like the following:

我还尝试过如下发布前":

What I have tried also is making a "before launch" as follows:

推荐答案

如果您将虚拟环境设置为 PyCharm 中的首选解释器,它将使用该特定虚拟环境来运行其脚本.但是,您也可以利用我们的运行配置提供的一些功能.

If you set your virtual environment as your interpreter of choice in PyCharm, it will use that particular virtual environment to run its scripts. However, you can also take advantage of some of the functionality that our run configurations provide.

您可以查看整个配置窗口的Before Launch"部分以输入您要执行的脚本.

You can check out the "Before Launch" part of the whole configuration window to enter scripts that you want executed.

设置好配置后,您就可以继续运行或调试配置.此外,如果您只想获取环境变量,则只需将环境变量放入环境变量"框中即可.

Once you've set your configurations, you can then go on to run or debug the configuration. Furthermore, if it is just environment variables that you want to source, you can just put in the environment variables in the "Environment Variables" box.

如果你想运行一个 shellscript,你需要像这样创建一个新的 shell 配置:

In case you want to run a shellscript, you will need to create a new shell configuration like so:

添加该配置后,您可以稍后继续引用它.

Once you've added that configuration, you can then go on to reference it later.

您现在将看到您可以引用相关配置:

You will now see that you can reference that configuration in question:

这篇关于如何在pycharm中获取额外的环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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