python解释器path变量,如何使用PyCharm为远程Python解释器保留环境变量

I am using a remote Python interpreter (a virtual environment created using pew) that I access via ssh. This is working fine when manually ssh'ing to the server and using the interpreter. However when using PyCharm to call it, it forgets about the environment variables that I export in my .bashrc.

It seems when calling the Python Interpreter via ssh, PyCharm (even though started from bash) ignores the .bashrc. Here it is indicated that a shell wrapper is the solution.

#!/bin/bash -l

/path/to/interpreter/bin/python

But simply giving PyCharm this shell file as an Interpreter doesn't work (package management is disabled and when running py-code a Python terminal opens...).

How do I get a "shell wrapper" that makes sure .bashrc is executed before the PyCharm remote Python-interpreter is run?

I made sure that PyCharm runs with the correct environment. All local interpreters don't show that problem (testing in PyCharm terminal and with a Python script:)

import os

print(os.environ)

I am also aware of the "Edit Configuration" option for running specific files and the possibility to set environment variables there, however it is tedious to that for each project/file and not what I'm looking for.

解决方案

You want your wrapper to contain the "$@" when calling python in your wrapper:

#!/bin/bash -l

/path/to/interpreter/bin/python "$@"

With that trick I somehow managed to setup pycharm on Windows while using virtualenv in WSL (Ubuntu bash) and retrieving my WSL env variables.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值