Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

python - Pycharm environment different than command line

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'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...