Pycharm环境不同于命令行

Pycharm environment different than command line(Pycharm环境不同于命令行)

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

问题描述

我在让我的 Pycharm 环境与我在命令行上的环境相匹配时遇到问题.我最近删除了 python 并通过 home brew 重新安装了它.我路径中的 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(True)

<块引用>

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

解决方案

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

从命令行(从 bash)运行 PyCharm.因此环境变量将从 bash 继承到 pycharm.阅读 $man environ 了解有关 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环境不同于命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Pycharm环境不同于命令行

基础教程推荐