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'
Use PyCharm features from the command line: open files and projects, view diffs, merge files, apply code style, formatting, and inspect the source code.
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.
.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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With