Pycharm environment different than command line(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环境不同于命令行
基础教程推荐
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
