psycopg2 installed successfully, but cannot be imported into python - python

I recently installed psycopg2 to my computer using macport. I followed the instructions on the Psycopg2 website:
sudo port install py27-psycopg2
When I used
port install
, psycopg2 was listed as successfully installed by macport.
However, whenever I type
import psycopg2
in python, it also give me the errors that there is no such modules in python. I am a novice in computer science. I looked up some questions kind of remsemble mine, but I could figure out what is going on. I hope everyone can help me out with this. I really appreciate your help and your time.

do
$ sudo port select --list python
This will list all the python installations. e.g:
none
python26-apple
python27 (active)
python27-apple
python33
python34
Now select the python27 that is installed by MacPorts:
sudo port select --set python python27
Now do
which python
For me, macports installed python at
/opt/local/bin/python

Try installing psycopg2 with python's native package manager 'pip', you've already got python installed on your mac, so typing :
pip install psycopg2
directly into your terminal's command line will install the module in the same python stack you are using to run the rest of your program.
If pip is not working see this answer to install it :
How do I install pip on macOS or OS X?

Related

Why Python library import doesn't work via NRPE

I'm developing plugin Nrpe in Python.
When i try to execute my code it works well on my machine. But when the NRPE execute it, an error occurs : 'No Module named pycurl'
I'm working on CentOs6.10 with Python 3.4 and i've installed pycurl with easy-install, the path to pycurl.py is /usr/lib/python3.4/site-packages//usr/lib/python3.4/site-packages/pycurl.py
And my PYTHONPATH = ['/usr/local/bin', '/usr/lib64/python34.zip', '/usr/lib64/python3.4', '/usr/lib64/python3.4/plat-linux', '/usr/lib64/python3.4/lib-dynload', '/usr/lib64/python3.4/site-packages', '/usr/lib/python3.4/site-packages']
I hope somebody could help me ?
Thanks !
You probably need something like:
python3 -m pip install pycurl
You may want to use: python3 -m pip install --user pycurl
or a virtual environment.
pycurl doesn't come with python. You have to install it with pip from pypi.

How can I instal cx_Oracle package to Anaconda 3 to use with python 3.5

I need to connect to Oracle database in Python Anaconda3-2.5.0-Windows-x86_64. Installation of the cx_Oracle module by:
conda install -c https://conda.anaconda.org/anaconda cx_oracle
fails with following output (trimmed):
Hint: the following packages conflict with each other:
- cx_oracle
- python 3.5*
So I tried to install package for Python 3.5 by 'cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe' from https://pypi.python.org/pypi/cx_Oracle/ Which seems to be working (somehow). Even 'conda list' command prints line:
cx-oracle 5.2.1 <pip>
But when I enter import cx_Oracle; in Python then
ImportError: DLL load failed: Uvedený modul nebyl nalezen.
appears. Rough translation of last localized part is 'Modul not found.'
How can I install the cx_Oracle module? Or is there any other way to connect to Oracle database?
I'm assuming that you have windows and python 3.5 only installed. Check your anaconda just incase to make sure you are using anaconda3 or that anaconda is setup with python3 environment. Assuming all that checks out and you are still getting that same error try doing a fresh install of cx_oracle from pip.
On your windows machine open up cmd and type pip install cx_Oracle and it should install nicely. If you by chance have python2 installed as well you might want to do python3 -m pip install cx_Oracle. After installation completes you should be good to go.
In the Anaconda navigator, select 'Environments', then on the right, change the filter to 'All'. Now you can query for 'cx_oracle', select it and at the bottom, select 'Apply'. Once completed, you should be able to
import oracle
Download a precompiled version of the package and install it using easy_install.
Easier way to load is to down load from the below link
https://pypi.python.org/pypi/cx_Oracle/
and install it in Windows. It worked like a charm for me.
From https://anaconda.org/anaconda/cx_oracle
conda install -c anaconda cx_oracle

Installing Pyqt4 with brew

Im working with brew to install PyQt on python3 but I cant seem to get it to work
I ran brew install pyqt and brew doctor to fix all possible errors but still when running my code I keep getting
ImportError: No module named 'PyQt4'
If I run echo $PATH im getting /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin
Can someone please guide me on fixing this problem? I am also using PyCharm but I still get the same error if I run in terminal python3 then import pyqt
please help me :( im really new in this but I tried everything that I could find in google
thanks!
PD: Running brew test pyqt does not bring an error but it does not open. Also I installed python3 with brew and im currently running it from /usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/bin/python3.4
If you want to use PyQt4 with Python 3, you should use this command to tell homebrew:
brew install PyQt --with-python3
I had the exact same problem. Installing using the instructions of Longhanks did not work as it said it was already installed.
I got it working with
brew reinstall PyQt --with-python3
The following method is for python 2.7. You can replace the 2.7 into your current python version like 3.4 (enter the directory to see which to use).
Because by default the python package is installed in /usr/local/lib/python2.7/site-packages which is not included in python library
try:
mkdir -p /Users/zgf/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/zgf/Library/Python/2.7/lib/python/site-packages/homebrew.pth
where zgf should be replaced by your username in OSX.
You can also copy the relevant files from /usr/local/lib/python2.7/site-packages into your personal python site package directory or public site package directory (/Library/Python/2.7/site-packages) if you can root.

Import Error: No module named AppKit

I use Mac OS X Lion and Python 2.7. I am new to python. Can anyone tell me how to import AppKit and PyObjC to Python. But i get the errors when trying to import Import Error: No module named AppKit or 'Import Error: No module named PyObjC.
Trying easy_install does not help either.
What can i do to import these 2 modules?
If not already installed, install pip by running:
sudo easy_install pip
Then run:
## install for all users
sudo pip install pyobjc
or
## install for current user only
pip install pyobjc --user
NOTE: the general recommendation is to avoid using the system python, and use instead a user-maintained version, for example installed via brew install python3, macports, conda or whatever you already use for third party dependencies.
If you're on Mac it could be you're using the incorrect pip version, try sudo pip3 install -U pyobjc that solved it for me.
This a good guide on how to install PyObjc: http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/
When I was trying to install PyObjc I found it quite hard, but after a while, (and lots of google searches) I got it working.
Edit
I've found a more modern guide on how to do this. Download the templates and put them into your ~/Library/Developer/Xcode/Templates/ directory, and everything should work correctly.
If you are using PyCharm, you should install PyObjC package manually within it because of venv I guess. This was the only working solution for me.
In my case none of them worked. I was using Anaconda in my mac, later I discovered that the main issue with the Anaconda. Then I installed PyObjC with it's all supporting libraries inside Anaconda in a specific Environment.
I run the command line by clicking the Environment play icon and run my script.
It worked without any issues :)

Python: import cx_Oracle ImportError: No module named cx_Oracle error is thown

I try to write a script in .py for oracle connectivity:
#!/usr/bin/python
import cx_Oracle
connstr='username/pwd#database'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()
curs.execute('select * from table1;')
print curs.description
for row in curs:
print row
conn.close()
I get the following error:
Traceback (most recent call last):
File "test_SQLPython.py", line 3, in ?
import cx_Oracle
ImportError: No module named cx_Oracle
Any help would be appreciated?
Thanks.
Tried installing it via rpm posted in above answers, but it didn't worked. What worked instead is plain pip install.
pip install cx_oracle
The above command installed cx_oracle=6.1
Please note that I'm using python 2.7.14 Anaconda release and oracle 12c.
Windows help:
Get the instant client from here.
Put the directory into your PATH variable.
Go to the command prompt (Win+R and type cmd) and set 2 variables matching your location- for example:
set TNS_ADMIN=C:\instant_client\instantclient_11_2
set ORACLE_HOME=C:\instant_client\instantclient_11_2
Then install the cx_Oracle module from an exe. If you use pip or easy_install, ...good luck.
You can get the installer here: https://pypi.python.org/pypi/cx_Oracle/5.1.3
For me the problem was that I had installed cx_Oracle via DOS pip which changed it to lower case. Installing it through Git Bash instead kept the mixed case.
In my case the solution was to use:
python3 -m pip install cx_Oracle --upgrade --user
instead of
pip3 install cx_Oracle
It was caused by some mess in pip, so I haven't got cx_Oracle installed properly:
# python3 -m pip -V
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
# pip3 -V
pip 21.2.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
I hope it'll save someone a few hours of life...
I have just faced the same problem. First, you need to install the appropriate Oracle client for your OS. In my case, to install it on Ubuntu x64 I have followed this instructions https://help.ubuntu.com/community/Oracle%20Instant%20Client#Install_RPMs
Then, you need to install cx_Oracle, a Python module to connect to the Oracle client. Again, assuming you are running Ubuntu in a 64bit machine, you should type in a shell:
wget -c http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
sudo alien -i cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
This will work for Oracle 11g if you have installed Python 2.7.x, but you can download a different cx_Oracle version in http://cx-oracle.sourceforge.net/
To check which Python version do you have, type in a terminal:
python -V
I hope it helps
I had a similar problem, you gotta make sure you have:
oracle instant client
cx_Oracle binary( from SourceForge )
Python
IMPORTANT: Make sure they are ALL either 64-bit or 32-bit, mixing is gonna cause problems
Windows and Anaconda help
Anaconda 4.3.0 comes with Python 3.6 as the root. Currently cx_Oracle only supports up to 3.5. I tried creating 3.5 environment in envs, but when running cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe it installs in root only against 3.6
Only workaround I could find was to change the root environment from 3.6 to 3.5:
activate root
conda update --all python=3.5
When that completes run cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe.
Tested it with import and worked fine.
import CX_Oracle
Although silly mistake but make sure to use correct module name and respect capitalization
I installed this package via command line as pip install cx_oracle in my windows machine. While importing it in spyder as cx_oracle, it kept on giving following error:
ModuleNotFoundError: No module named 'cx_oracle'.
Upon correcting the module name in import command to cx_Oracle (i.e. capital letter 'O' in oracle), it was a successful import.
To access Oracle from python you need (additionally) the cx_Oracle module. The module must be located either in the system python path or you have to set the PYTHONPATH appropriate.
Unknown92 answer helped me (on windows).
Note that all versions must fit.
I've downloaded cx_Oracle here, for me the file cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe worked with:
Python 3.5.1 64bit. for some reason the default download link from the main page is for the 32bit version.
And oracle instance client 12.1.0.2.0 (the file named instantclient-basic-windows.x64-12.1.0.2.0.zip) here.

Categories

Resources