Importing pyFileMaker complains about EXPAT library - python

I've just downloaded pyFileMaker. I copied the directory PyFileMaker into the dir Lib under Python31 directory, but when I simply include the module FMServer with this line:
from PyFileMaker import FMServer
I get this error
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from PyFileMaker import FMServer
File "C:\Python31\lib\PyFileMaker\__init__.py", line 17
print "Unable to load the EXPAT library. You need to have it installed"
I checked whether the module expat exists and, infact, it exists. How can I fix this?

Well, as far as I can see the error happened not in the import, but in the print statement. (I.e. there probably was an error in import too, but it was intercepted.) The problem is that PyFileMaker is written for Python 2.x (their site says 2.4 is the minimal version), while you're using Python 3, and v3 is not compatible with v2.x.
I'd suggest switching to Python v2.7 (which is the primary version at the moment anyway). If you really want to use v3, you might try to convert the file with the 2to3 converter, but there's no guarantee it's going to work.

Related

DLL load failed, module not found?

I have a folder with a file "main.py" and a file "_test.pyd" (note .pyd). The file "main.py" looks like this:
import _test
I get the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import _test
ImportError: DLL load failed while importing _test: The specified module could not be found.
Why is this error coming up? Cheers.
Note: I was given this code by others, and it works for the original authors, so I'm not sure what's wrong with me/my machine.
Update: Running os.path.isfile('_test.pyd') returns True, so I don't think it's a problem with the path
You should append the path of the folder which contains the imported module before import.
Code:
import os
import sys
sys.path.append(os.path.realpath(os.path.dirname(__file__)))
import _test # noqa: E402
EDIT:
Other ideas:
Adding __init__.py file to the related director.
Checking the PyInit_foo() function in .pyd file.
If the Python finds the .pyd file, it will attempt to call PyInit_foo() to initialize it
Update Following posts from people experiencing similar issues, I tried downgrading my Python version (from 3.8.4rc1 to 3.5.4) and the import now works correctly. No clue why. I guess the .pyd file was written in that version of Python (I'm not the author of the file), but still I'm clueless as to what the exact origin of the problem is.
I've been through this error and what I found after a lot of investigation:-
issue was in Opencv==4.5.1 build from source with cuda and flag cuda_with_fast_math=on
I just rebuild OpenCV and disable
cuda_with_fast_math
and it works for me.

Syntax Error using import ctypes

I'm new to python and have installed Python2.6
directory address of python is "C:\Python26"
I tried to use import ctypes
I'm getting below errors
Traceback (most recent call last):
File "C:\Python26\Lib\msdecmiolib\__init__.py", line 22, in <module>
import ctypes
File "C:\Python26\Lib\ctypes\__init__.py", line 25
5DEFAULT_MODE = RTLD_LOCAL
^
SyntaxError: invalid syntax.
Something's wrong with your Python installation; that line in ctypes/__init__.py should simply read
DEFAULT_MODE = RTLD_LOCAL
It's hard to imagine how that could have happened other than accidentally -- maybe you opened the file to look at it and accidentally hit 5 before saving? Anyway, you can either fix it yourself and see what happens or if you'd prefer reinstall Python.
(Possibly upgrading to at least 2.7 while you're at it, which would be a good idea unless there's some peculiar reason you can't, although that's up to you.)

NLTK - No module named corpus

After installing NLTK and NLTK-DATA with PIP, i run python then i type from nltk.corpus import cmudict and it works.
But when i wrote a script like this:
from nltk.corpus import cmudict
d = cmudict.dict()
def nsyl(word):
return [len(list(y for y in x if y[-1].isdigit())) for x in d[word.lower()]]
print nsyl("hello")
I have the following error :
Traceback (most recent call last):
File "nltk.py", line 1, in <module>
from nltk.corpus import cmudict
File "nltk.py", line 1, in <module>
from nltk.corpus import cmudict
ImportError: No module named corpus
How can i fix this ?
Thanks in advance
From your stacktrace: File "nltk.py", line 1, in <module>, you have called your file nltk.py. When python searches for a module, it looks in the current directory first, and you have "nltk.py" there. It will import this as nltk, and since your code does not define corpus, it can't find nltk.corpus.
To fix this, you should rename your file to something else, say nltkexperience.py. Also make sure to remove "nltk.pyc" from your directory if it exists, since this will also be loaded (it's the byte compiled version of your code). After that, it should work fine.
As others have pointed out, this seems to be a case of version mismatch. If you have multiple versions of Python installed, make sure that the one where you installed NLTK is the one being used when running the script.
As an example, I have Python 2.7, Python 3.3, and Anaconda Python (2.7) installed. My shell defaults to Anaconda (and its pip, e.g.). So when I install something via pip and run it on the command line, it works. At the same time, my Vim is compiled to use the system's Python, and it doesn't see Anaconda's installs/ libraries. So if from within Vim I run Python, I will get an error that the library I installed is not found.
Hope this helps.

Raspberry Pi Python Program First Line Error/Python Library Error

The first two lines of the program are:
from i2clibraries import i2c_lcd
from ABElectronics_ADCPi import ADCPi
No matter what line is first the Pi returns an error when I attempt to run it under Python or Python 3. All the libraries are possessed and registered. Using the shell commands the checks saying the exports worked correctly all show up correctly. However, whatever line is line 1 will return a missing module error and the i2clibraries will always return a missing module error. By keeping that as the first line I get the least errors in running, but the program still returns this:
pi#raspberrypi ~ $ sudo python file.py
Traceback (most recent call last):
File "file.py", line 1, in <module>
from i2clibraries import i2c_lcd
File "/home/pi/i2clibraries/i2c_lcd.py", line 1, in <module>
from i2clibraries import i2c
File "/home/pi/i2clibraries/i2c.py", line 1, in <module>
from quick2wire.i2c import I2CMaster, writing_bytes, reading
ImportError: No module named quick2wire.i2c
Given the error, what possible solutions are there to stop the first line from being unable to find its module?
Problem
The error message is telling you that when you try to import the i2clibraries module, the imports that it requires (dependencies) cannot be found when it is itself is being imported. This is specifically in the first line of i2c.py file - where the line
from quick2wire.i2c import I2CMaster, writing_bytes, reading
is failing.
The problem is almost certainly that your modules are not on the Python module search path. Further info on this is given at the end of this answer should you need it.
Solution
There are a number of ways to resolve this. The one recommended by the developers of the module is
To use the library without installation, add the full path of the
source tree to the PYTHONPATH environment variable. For example:
export QUICK2WIRE_API_HOME=[the directory cloned from Git or unpacked from the source archive]
export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME
So, you need to know where your quick2wire libraries are installed - from your error message, I would hazard a guess that they are in /home/pi/i2clibraries/, so $QUICK2WIRE_API_HOME=/home/pi/i2clibraries/ should be your first line of the above pair.
Further info
You can read more generally about how to install modules on Python 2.x on the Python website. You can look at what paths make up the module search path by going to an interactive Python prompt (i.e. typing python) and then doing.
>>> import sys
>>> sys.path
This will output a list containing strings representing all the paths that will be searched for modules.

What does ImportError mean in Python?

I try to import a module:
import cv
And I get the following error message:
ImportError: DLL load failed: The specified module could not be found.
But if I try to import a library that definitely does not exist, for example:
import blabla
I get:
ImportError: No module named blabla
So, I conclude the the cv library is not totally hidden. Python is able to see something. Does anybody know what Python is able to see and what is missing?
ADDED
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ADDED 2
In the directory that contains the cv library there is sub-directory (C:\OpenCV2.2\bin) with many *.dll files. So, I tried:
import sys
sys.path.append("C:\OpenCV2.2\bin")
and I still get the "dll load failed". Is there a way to find out which exactly "dll" file is missing. I mean, Python tries to find a specific dll file (let say cv.dll) and cannot find it?
In this particular case, "DLL load failed" is caused by using Python 2.6 with OpenCV 2.2. You should use Python 2.7, because cv.pyd is linked with python27.dll.
ImportError can be confusing because it can be thrown when the module you are trying to import tries to import something else and because all of the import code is written in C you don't always get a useful backtrace.
In this case it looks as though either cv itself is a DLL, or some module that it tries to import is a DLL. The DLL won't load because it depends on some other DLL that isn't present on your system.
If you can't easily see what dependency is missing you can try using Microsoft's 'depends' tool to find out.
Most probably Python finds the pure-python module cv, which cannot find a DLL it needs.

Categories

Resources