Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm environment different than command line

Tags:

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'

like image 373
CLJ Avatar asked Oct 31 '13 20:10

CLJ


People also ask

Can you run command-line in PyCharm?

Use PyCharm features from the command line: open files and projects, view diffs, merge files, apply code style, formatting, and inspect the source code.

What environment does PyCharm use?

So back to your question, when you create an env in Pycharm, it will ask you which env do you want to create: Virtualenv Environment , Conda Environment , or Pipenv Environment . As for me, I usually choose Pipenv Environment as this env will be bound to the current project and can generate a lock file.


2 Answers

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

like image 159
DmitryFilippov Avatar answered Sep 23 '22 19:09

DmitryFilippov


If you are using PyCharm version 2016.3 and have noticed that your PyCharm Terminal is no longer providing the same default environment as your MacOs Terminal environment, it is a bug that should be fixed in 2016.3.1 - whenever it releases. In the mean time, the following is a workaround that should 'default' all of your PyCharm projects back a more more MacOS-Terminal like PyCharm-Terminal:

Create a ~/.bashrc file with the following contents: source /etc/bashrc source /etc/bashrc_Apple_Terminal source ~/.bash_profile

This should setup your PyCharm Terminal (interactive bash session) and make it similar to the MacOS Terminal (login bash session). Once JetBrains patches and releases 2016.3.1, I recommend deleting this ~/.bashrc file. Hopefully this will get us all back to normal.

like image 29
cmlccie Avatar answered Sep 21 '22 19:09

cmlccie