I installed pyscopg3 on my venv using pip install psycopg[binary] as per the documentation but I still get an import error:
Exception has occurred: ImportError
no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: DLL load failed while importing pq: The specified module could not be found.
- couldn't import psycopg 'python' implementation: libpq library not found
I'm running a Windows 10 machine. How can I solve this error?
You need to install the command line tools on PostgreSQL on your Windows machine.
Download the full server installer here: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
You don't need to install the full server package, only command line tools in the installer options will be necessary:
After the installation, you need to add the PostgreSQL bin folder in your PATH environnement variable:
hit +R at the same time to get command prompt. Then type sysdm.cpl, go to advanced and select "Environment Variables", in PATH add the path to :
C:\Program Files\PostgreSQL\13\bin\ folder (or whatever folder you choose to install the PostreSQL commande line tools).
IMPORTANT: do not forget to close and restart your dev environnement (ie: VSCode, PyCharm, ...) to take the new environnement variable into account.
Note : This answer is related to Windows machine. For Linux the installation of a at least one postgresql-client-<version> package will be enough.
related to: https://stackoverflow.com/a/60369228/5341247
Related
I installed Anaconda (Anaconda3-2020.07-Windows-x86_64, python 3.8). Following the installation guide, I didn't add Anaconda to the PATH environment variable. After installation, it works well when using Anaconda Prompt to start python.
Problem occurs when I use Python Launcher to start python from CMD:
In CMD, type "py" to launch python(The Python Launcher is able to find Anaconda python). Then when I attempt to import numpy, I get the following error:
Original error was: DLL load failed: The specified module could not be found.
And when I attempt to import sqlite3, I get the following error:
ImportError: DLL load failed while importing _sqlite3: %1 is not a valid Win32 application
If I use Anaconda Prompt to start python, I can suscessfully import numpy and sqlite3. I checked sys.path under these two situations and they are exactly the same.
Why? What's the difference between the two situations?
p.s.
I'm concerned with this problem because I built a website using "django + mod_wsgi + Apache", and when visiting the website from brwoser, the website got an "Internal Server Error". The error log shows that it is caused by the failure of importing numpy and sqlite3, just like the above errors.
What's the difference between the two situations?
The anaconda command prompt has added a bunch of paths to the PATH environment variable, e.g. for me it has added all of these locations:
C:\ProgramData\Miniconda3
C:\ProgramData\Miniconda3\Library\mingw-w64\bin
C:\ProgramData\Miniconda3\Library\usr\bin
C:\ProgramData\Miniconda3\Library\bin
C:\ProgramData\Miniconda3\Scripts
C:\ProgramData\Miniconda3\bin
C:\ProgramData\Miniconda3\condabin
In some of these locations there are executables like python.exe so that calling python will launch the anaconda installed version. Other folders in this list contain .dll files, i.e. libraries that your modules might depend on (like numpy or sqlite that are interfaces to functions written in c/c++). So even if you are calling the right python.exe, if the PATH is not set to include the locations of the neccessary dlls, then importing such packages will fail, as you can see in your error messages:
Original error was: DLL load failed: The specified module could not be found.
What you can do:
I am not an expert on configuring a django server, but by manually adding these locations to your PATH, you might be able to solve the issue.
I keep getting this error in python from trying to call qgis from a script.
The code is:
from qgis.core import *
from qgis.analysis import *
I have read every posting on SO about this; wiped QGIS and reinstalled. Reset my PYTHON_PATH and QGIS_PREFIX variables to the correct directory. I've also checked the dependencies via dpkg -l | grep qgisand all of my dependencies are the xenial version.
Any other suggestions?
I had the same problem but it was with Windows 7. Following the last point called Running Custom Applications in http://docs.qgis.org/2.8/en/docs/pyqgis_developer_cookbook/intro.html I solved it.
You will need to tell your system where to search for QGIS libraries and appropriate Python modules if they are not in a well-known location — otherwise Python will complain:
>>> import qgis.core
ImportError: No module named qgis.core
This can be fixed by setting the PYTHONPATH environment variable. In the following commands, qgispath should be replaced with your actual QGIS installation path:
on Linux: export PYTHONPATH=/qgispath/share/qgis/python
on Windows: set PYTHONPATH=c:\qgispath\python
The path to the PyQGIS modules is now known, however they depend on qgis_core and qgis_gui libraries (the Python modules serve only as wrappers). Path to these libraries is typically unknown for the operating system, so you get an import error again (the message might vary depending on the system):
>>> import qgis.core
ImportError: libqgis_core.so.1.5.0: cannot open shared object file: No such file or directory
Fix this by adding the directories where the QGIS libraries reside to search path of the dynamic linker:
on Linux: export LD_LIBRARY_PATH=/qgispath/lib
on Windows: set PATH=C:\qgispath;%PATH%
These commands can be put into a bootstrap script that will take care of the startup. When deploying custom applications using PyQGIS, there are usually two possibilities:
require user to install QGIS on his platform prior to installing your application. The application installer should look for default locations of QGIS libraries and allow user to set the path if not found. This approach has the advantage of being simpler, however it requires user to do more steps.
package QGIS together with your application. Releasing the application may be more challenging and the package will be larger, but the user will be saved from the burden of downloading and installing additional pieces of software.
The two deployment models can be mixed - deploy standalone application on Windows and Mac OS X, for Linux leave the installation of QGIS up to user and his package manager.
Finally got it working. Had to completely wipe and reinstall QGIS twice and separately remove python-qgis. Also had to uninstall anaconda. After the second fresh install of QGIS I've gotten it working.
No other changes to my configuration.
When I run a python script that I set up on WebJobs in Azure - I get the following error:
import MySQLdb
ImportError: No module named MySQLdb
job failed due to exit code 1
I found some articles that seem to suggest to install python modules to a directory created on the webapp. How/Where would I install those modules?
Have you tried this?
http://nicholasjackson.github.io/azure/python/python-packages-and-azure-webjobs/
(from the site):
Step 1.
If you are using OSX and the default Python 2.7 install your packages
installed with pip will be in /usr/local/lib/python2.7/site-packages,
create a folder called site-packages in the root of your python job
and copy any packages you need for your job into it.
Step 2
Next you need to modify your run.py or any other file which requires
access to the package files. At the top of the file add….
import sys
sys.path.append("site-packages")
I am having weird behaviors in my Python environment on Mac OS X Lion.
Apps like Sublime Text (based on Python) don't work (I initially thought it was an app bug),
and now, after I installed hg-git, I get the following error every time I lauch HG in term:
*** failed to import extension hggit from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-package/hggit/: [Errno 2] No such file
or directory
So it probably is a Python environment set up error. Libraries and packages are there in place.
Any idea how to fix it?
Notes:
I installed hg-git following hg-git web site directions.
I also added the exact path to the extension in my .hgrc file as: hggit = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-package/hggit/
Python was installed using official package on Python web site.
Echoing $PYTHONPATH in term print anything
"site-package"? Did you mean "site-packages"?
I used this question/answer to install DB2 in Lion: How do I install IBM DB2 Express-C on Mac OS X 10.7 Lion?
After configuring my databases, I am able to use db2 from the command line to execute queries, but the python modules ibm_db and PyDB2 both fail to import with the following error:
>>> import ibm_db
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/ibm_db-1.0.4-py2.7-macosx-10.7-intel.egg/ibm_db.so, 2): Symbol not found: _dsIsDirServiceRunning
Referenced from: /Users/<username>/sqllib/lib64/libdb2.dylib
Expected in: /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService
How can I fix this and get ibm_db and PyDB2 to work properly with DB2 in Lion?
edit: moved answer to answers
Answer:
The problem is that a particular symbol in the DirectoryService framework was finally removed in Lion (it was deprecated in 10.2). libdb2.dylib, which is installed by DB2 Express-C attempts to call this function, and causes the error when importing either python module.
To work around this, you need to configure your environment to link against an older version of the DirectoryService framework. To do this, you will need an installation of Snow Leopard (it may work with older versions, but I have not tested it, and you will want the newest you can get your hands on, that isn't Lion, of course). You will find the DirectoryService framework installed here:
/System/Library/Frameworks/DirectoryService.framework/
Copy that directory from a Snow Leopard installation to any location you want in your Lion installation. For this example, I copied the DirectoryService.framework directory into a directory named OldFrameworks in ~ :
~/OldFrameworks/DirectoryService.framework/
Set the environment variable $DYLD_LIBRARY_PATH to contain the path to the actual library:
export DYLD_LIBRARY_PATH=${HOME}/OldFrameworks/DirectoryService.framework/Versions/Current/:${DYLD_LIBRARY_PATH}
Any environment in which you perform the above command will be configured to allow python to import ibm_db or PyDB2. Add it to your .profile, .bashrc, etc. to permanently configure your environment. Remember, though, this means all commands executed in the configured environment will attempt to link against the snow leopard version of DirectoryService. This could potentially cause errors with other tools (I have yet to encounter any). It would be prudent to only set DYLD_LIBRARY_PATH in shells where you need it.
You can change the db2 libraries using install_name_tool to look at the copied version of DirectoryService.framework, so you don't have to change DYLD_LIBRARY_PATH
Full credit goes to the following, I am simply updating this thread having been through the process of install db2 / ibm_db on Lion and finding this thread as one of the top hits via Google.
http://www.ibm.com/developerworks/forums/thread.jspa?threadID=238136&start=30&tstart=0
with other options described here:
http://www.ibm.com/developerworks/forums/message.jspa?messageID=14604855#14604855
The answer (should the above thread disappear):
Copy the Snow Leopard DirectoryService.framework to
/opt/SL_Frameworks/DirectoryService.framework
Then
cd /opt/IBM/db2/V9.5/
install_name_tool -change /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService /opt/SL_Frameworks/DirectoryService.framework/Versions/A/DirectoryService lib64/libdb2sec.dylib
install_name_tool -change /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService /opt/SL_Frameworks/DirectoryService.framework/Versions/A/DirectoryService lib64/libdb2.dylib
The referenced post mentions changing a third library
libdb2e.dylib
however, I have only installed the db2 client to use the ibm_db python module and this library is not present.
The easiest solution to install ibm_db on MacOS is to run the below command:
pip3 install --no-binary "ibm_db" ibm_db
Regards,