0

I have been trying to install psycopg2 in PyCharm, but I keep running into this error:

>>> pip install psycopg2
File "<input>", line 1
pip install psycopg2
          ^
SyntaxError: invalid syntax

I've already managed to install psycopg2 in a virtualenv outside of PyCharm. However, PyCharm doesn't recognize that installation, and it seems that I have to install it separately from inside PyCharm. As a result when I run the project in PyCharm I get this error: ImportError: No module named 'psycopg2'. I'm a beginner to PyCharm--and, frankly, to Python development--so any help would be greatly appreciated.

Laravel Linguist
  • 39
  • 1
  • 1
  • 6

2 Answers2

3

Given your use of '>>>', it appears that you are trying to install psycopg2 from within Python. Exit the Python shell and run the command.

If you are in IPython, you can prepend your command with an exclamation to run it as a command instead of as Python code:

In[1]: !pip install psycopg2
davidism
  • 121,510
  • 29
  • 395
  • 339
Alexander
  • 105,104
  • 32
  • 201
  • 196
  • Thanks, Alexander. I'm trying to install `psycopg2` from within the Python Console in PyCharm. That command didn't work unfortunately, and I'm getting this error: `SyntaxError: invalid syntax`. – Laravel Linguist May 24 '15 at 16:14
  • In which case you'll need: $ pip install psycopg2 (Note that you don't type the '$' sign, it just indicates that you need to execute this command from a terminal window). – Alexander May 24 '15 at 16:16
  • That worked once I switched my interpreter to Python 2.7.6. However, I ran into the same errors that I did when I switched my interpreter to my virtualenv, which already had all the packages I needed installed – Laravel Linguist May 24 '15 at 17:20
  • Can you be more specific about the errors? You may also want to refer to this article: http://stackoverflow.com/questions/27264574/import-psycopg2-library-not-loaded-libssl-1-0-0-dylib – Alexander May 24 '15 at 17:23
  • Once, I ran the `pip install psycopg2` command in my terminal, I had to switch my interpreter to Python 2.7.6 to pick up that new installation. However, I'm getting an operation error when I run my project with either Python 2.7.6 or my virtualenv as my interpreter. Here's the error: `peewee.OperationalError: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?` – Laravel Linguist May 24 '15 at 17:27
  • You may want to refer to the Psycopg2 Installation Instructions http://initd.org/psycopg/docs/install.html. – Alexander May 24 '15 at 17:37
  • I've got it installed now. It's just that in doing so, a new issue has popped up: http://stackoverflow.com/questions/30426181/peewee-operationerror-in-pycharm – Laravel Linguist May 24 '15 at 17:39
2

Try

$ pip install psycopg2==2.4.5

or

$ pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz
davidism
  • 121,510
  • 29
  • 395
  • 339
Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52