Python: Failed to import extension - Errno 2 - python

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"?

Related

ImportError "no pq wrapper available" when importing psycopg3

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

Import Error when using Anaconda with Python launcher

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.

ImportError: No module named qgis.core ubuntu 16.04 python 2.7 qgis 2.16.2

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.

Error while installing wxPython package in a non-standard path

I am a relative newbie with Python and was trying to install wxPython 2.9 using Python 2.6. I did a build from source and then installed the package both being done in a non-standard (local) path. When I try and import wx (having provided the path to the installation folder in my environment variable), I get the following error message:
"ImportError:
libwx_gtk2u_xrc-2.9.so.1: cannot open
shared object file: No such file or
directory".
Can someone please tell me if I need to build gtk separately? And if yes, how do I go about doing it?
Add the directory containing the library given in the error to your ld search paths. See the ldconfig(8) man page for details.

Python: _socket.so

Greetings!
So I'm creating a Python script that will when finished be compiled with Shedskin. Currently we do a little FTP work in this script so we import the ftplib module. When I attempt to compile it with Shedskin we get the error back saying that there is no '_socket' file in our Python2.6 installation on Ubuntu. I've checked myself in the '/usr/lib/python2.6/lib-dynload' dir to confirm that yes there isn't any file entitled '_socket.so' present in that folder.
I've tried reinstalling the python2.6 package in Synaptic but to no avail.
What should I do?
Look for shdeskin supported library modules in
/usr/lib/python2.6/site-packages/shedskin/lib/.
My Fedora installation of shdeskin 0.7 does not include ftplib.

Categories