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环境不同于命令行
基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01