Pycharm 环境不同于命令行 [英] Pycharm environment different than command line

查看:53
本文介绍了Pycharm 环境不同于命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让 Pycharm 环境与命令行上的环境匹配时遇到问题.我最近删除了 python 并通过自制软件重新安装了它.我路径中的 python 指向 /usr/local/bin/python 我将 PATH=/usr/local/bin:$PATH 添加到我的 .bash_profile 的开头文件,我可以在命令行的 interperter 中很好地执行以下代码.但是,当我将 /usr/local/bin/python 添加到项目 python 解释器并运行以下代码时,我得到了属性错误.谁能解释一下我如何让 Pycharm 使用与我的命令行相同的环境?

导入 sqlite3db = "mydb.db"conn = sqlite3.connect(db)conn.enable_load_extension(真)

<块引用>

AttributeError: 'sqlite3.Connection' 对象没有属性 'enable_load_extension'

解决方案

.bash_profile 仅由 bash(您的命令行解释器)读取.但是,如果您想为 PyCharm 保留 bash 环境,则有一个真正的 Linux 方式.

从命令行(从 bash)运行 PyCharm.因此环境变量将从 bash 继承到 pycharm.阅读 $man 环境以获取有关 linux 环境继承过程的信息.所以你需要的只是从命令行启动 ${PATH_TO_PYCHARM}/bin/pycharm.sh .或者创建启动器来调用 bash 来启动 PyCharm.

就是这样!希望对你有用.

I am having an issue getting my Pycharm environment to match up with the environment that I have on the command line. I recently removed python and reinstalled it via home brew. The python in my path is pointing to /usr/local/bin/python I added PATH=/usr/local/bin:$PATH to the beginning of my .bash_profile file and I can execute the following code just fine in the interperter on the command line. However, when I add /usr/local/bin/python to the project python interpreters and run the below code I get the attribute error. Can anyone shed some light on how I can get Pycharm to use the same environment as my command line?

import sqlite3
db = "mydb.db"
conn = sqlite3.connect(db)
conn.enable_load_extension(True)

AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'

解决方案

.bash_profile is being read by bash (your command line interpreter) only. However if you want to preserve bash environment for PyCharm there is one true Linux way.

Run PyCharm from your command line (from bash). Thus environment variables will be inherited from bash to pycharm. Read $man environ for information on linux environment inheritance process. So all you need is just launch ${PATH_TO_PYCHARM}/bin/pycharm.sh from command line. Or create launcher which invokes bash for PyCharm launching.

Thats it ! Hope that works for you.

这篇关于Pycharm 环境不同于命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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