First of all, thank you very much for reading.
Some days ago I installed Python3 (3.6.9) and opencv 3.4.10 in an Ubuntu 18.04 desktop system. I needed to downgrade opencv to 3.4.0 after some compilation problems (not related to python3), so I removed opencv 3.4.10 by using the sudo make uninstall order, and tested that it was uninstalled as if I tried importing it in python I got the following error:
libopencv_hfs.so.3.4: cannot open shared object file: no such file or directory
I thought installing 3.4.0 version would solve the problem but now that it's installed, when I try to import it in a python3 script I am getting the same error. I think this error must be related to the way python3 references the import files. I think it's still pointing to the uninstalled version of 3.4.10, but I can not find the way to change it.
Could someone please help me with this issue?
Thank you very much.
Andrés.
Using a virtualenv would resolve the issue. Check this out on how to use : Installing packages using pip and virtual environments
Once you're done installing requirements in the virtualenv, run your python script there only to use the specified versions.
Hello again and thank you for you answers.
I have been able to solve the problem. Thought I had uninstalled the previous version of opencv, there was still a cv2.sofile in my python virtual environment path, and it had not been replaced by the new cv2.so, so python tried to import the old one instead of the new one.
The old cv2.so (the one that was referenced when I imported cv2 in python) was here --> ~/.virtualenvs/cv/lib/python3.6/site-packages/cv2.so
The cv2.so I wanted to be used when imported was here --> /usr/local/lib/python3.6/site-packages/cv2/cv2.so so I replaced the one in the virtual environment path with the one in the lib directory and that did the trick :)
I have followed all the steps shared in all stackoverflow and other questions out there to install gettext for windows (10), but still, I get the error: "Can't find msguniq, make sure you have gettext tools installed" when using internationalization in django. I have tried to download the files directly and added them to the PATH, and even an installer that had already compiled everything and added to the path automatically, but it still doesn't work, and I don't know what else to do... Help please!
Thank you for your time.
I had the same problem. I tried various solutions to no avail. Finally, I downloaded the binaries from https://mlocati.github.io/articles/gettext-iconv-windows.html
and it worked.
Not sure what problem you face but below command worked for me
pip install python-gettext
In windows you just need to download :
gettext-tools-xx.zip
gettext-runtime-xx.zip
from here: enter link description here
and then you need to unzip them and copy all in bin folder of both files into C:\Program Files\gettext-utils\bin and then you need to go to control panel-> system -> advanced -> environment variables and add this path:C:\Program Files\gettext-utils\bin to path variables. Note:
xx is the version you want to download if you download version 18 you will get an error that some dll file is missing, I suggest to download version 17
this folder: gettext-utils\bin does not exist and you need to create it
restart your pc before you use gettext
I'm trying to create a pdf file inside a python/django project. I'm using PyLatex, which helps, but it's generate_pdf method breaks when it calls pdflatex. I keep getting this error:
FileNotFoundError: [Errno 2] No such file or directory: 'pdflatex'
I tried everything - os.system() ... subprocess. Any way I try, it can't find pdflatex. I'm running on Windows, but I need to be able to to do this within the web-app anyway.
Thanks for any help!
You just need to install pdflatex (and you will need to install on your server when you release your web-app). Instructions for installing on windows can be found in the top answer here.
Do you have "pdflatex" installed? As per this question, you may have to install "MiKTeX" and point os.system() at C:\Program Files\MiKTeX <MikTeX version>\miktex\bin to make it work.
Hope that helps.
Do you have texlive installed? If yes, then the issue is with the system path variable. If not already added, add it to the system path.
#
Updated answer:
I took the time and decided to replicate your issue. I too use windows.
I copied the basic example from Pylatex and tested it on my machine, I was able to replicate the same error as you despite having TexLive installed. To solve it I did the following steps:
Installed MikTex (I believe you have it installed).
Tried running it again but failed with the error missing package latexmk.
Using MikTex package manager, I installed the latexmk package.
Tried running but still failed, error missing perl.exe command.
I had to install perl to my windows, use the following links -- https://learn.perl.org/installing/windows.html
When I tried again, it compiled successfully.
The issue was not having the package latexmk for MikTex and perl.exe of which you should have posted as part of the error logs. Try that and let me know if successful.
I have a situation very much like the one at Error "ImportError: DLL load failed: %1 is not a valid Win32 application", but the answer there isn't working for me.
My Python code says:
import cv2
But that line throws the error shown in the title of this question.
I have OpenCV installed in C:\lib\opencv on this 64-bit machine. I'm using 64-bit Python.
My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7. This folder contains cv2.pyd and that's all.
My PATH variable: Path=%OPENCV_DIR%\bin;... This folder contains 39 DLL files such as opencv_core246d.dll.
OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11.
The solution at Error "ImportError: DLL load failed: %1 is not a valid Win32 application" says to add "the new opencv binaries path (C:\opencv\build\bin\Release) to the Windows PATH environment variable". But as shown above, I already have the OpenCV binaries folder (C:\lib\opencv\build\x64\vc11\bin) in my PATH. And my OpenCV installation doesn't have any Release folders (except for an empty one under build/java).
What's going wrong? Can I tell Python to verbosely trace the loading process? Exactly what DLL files is it looking for?
I noticed that, according to http://www.dependencywalker.com/, the cv2.pyd in C:\lib\opencv\build\python\2.7 is 32-bit, whereas the machine and the Python I'm running are 64-bit. Could that be the problem? And if so, where can I find a 64-bit version of cv2.pyd?
Unofficial Windows Binaries for Python Extension Packages
You can find any Python libraries from here.
Please check if the Python version you are using is also 64 bit. If not then that could be the issue. You would be using a 32-bit Python version and would have installed a 64 bit binaries for the OpenCV library.
Wow, I found yet another case for this problem. None of the above worked. Eventually I used python's ability to introspect what was being loaded. For Python 2.7, this means:
import imp
imp.find_module("cv2")
This turned up a completely unexpected "cv2.pyd" file in an Anaconda DLL directory that wasn't touched by multiple uninstall/install attempts. Python was looking there first and not finding my good installation. I deleted that cv2.pyd file and tried imp.find_module("cv2") again and python immediately found the right file and cv2 started working.
So if none of the other solutions work for you, make sure you use Python introspection to see what file Python is trying to load.
In my case, I have 64-bit Python, and it was lxml that was the wrong version--I should have been using the x64 version of that as well. I solved this by downloading the 64-bit version of lxml here:
https://pypi.python.org/pypi/lxml/3.4.1
lxml-3.4.1.win-amd64-py2.7.exe
This was the simplest answer to a frustrating issue.
I just had this problem. It turns out it was just because I was using an 64-bit version of the OpenCV file. I tried the x86 and it worked.
I had the same problem. Here's what I did:
I downloaded the pywin32 wheel file from here, then
I uninstalled the pywin32 module. To uninstall, execute the following command in a command prompt.
pip uninstall pywin32
Then, I reinstalled pywin32. To install it, open the command prompt in the same directory where the pywin32 wheel file lies. Then execute the following command.
pip install <Name of the wheel file with extension>
Wheel file will be like: piwin32-XXX-cpXX-none-win32.whl
It solves the problem for me.
I copied cv2.pyd file from /opencv/build/python/2.7/x86 folder instead of from /x64 folder to C:/Python27/Lib/site-packeges. I followed rest of the instructions provided here.
Added by someone else, not verified: I also copy file cv2.pyd to folder C:/Python27/Lib/site-packages/cv2. It works.
For me the problem was that I was using different versions of Python in the same Eclipse project. My setup was not consistent with the Project Properties and the Run Configuration Python versions.
In menu Project → Properties → PyDev, I had the Interpreter set to Python 2.7.11.
In Run Configurations → Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.
If your build system (CMake in my case) copies the file from <name>.dll to <name>.pyd, you will get this error if the original file wasn't actually a DLL file. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib.
I discovered this error by loading the pyd file in Dependency Walker and finding that it wasn't valid.
Update NumPy.
pip install numpy --upgrade
It works for me!
This one worked for me:
pip install -- pywin32==227
I faced the same issue when I uninstalled and reinstalled a different version of 2.7.x of Python on my system using a 32-bit Windows Installer. I got the same error on most of my import statements.
I uninstalled the newly installed Python, downloaded a 64-bit Windows installer, reinstalled Python again, and it worked.
So I had problems installing vtk under Windows (as I use Python 3.7, there isn't any binary available so far. Just for older Python versions pip install vtk is not working)
I did wrote Python in my cmd:
Python 3.7.3 on win32
So I now know I have Python 3.7.3 running on a 32 bit.
I then downloaded the correct wheel at VTK‑8.2.0‑cp37‑cp37m‑win32.whl
Next I installed that wheel:
pip install VTK-8.2.0-cp37-cp37m-win32.whl
Then I tested it and it worked:
python
import vtk
I experienced the same problem while trying to write code concerning speech-to-text.
The solution was very simple. Uninstall the previous pywin32 using the pip method:
pip uninstall pywin32
The above will remove the existing one which is by default for 32 bit computers. And install it again using
pip install pywin32
This will install the one for the 64 bit computer which you are using.
I had a similar issue while trying to run uvicorn,
Creating a new virtual environment and reinstalling the python packages worked
You can install opencv from official or unofficial sites.
Refer to this question and this issue if you are using Anaconda.
It has a very simple solution.
After installing opencv
place
cv2.pyd from C:\opencv\build\python\2.7\ **x64** to C:\Python27\Lib\site-packages
instead of, place cv2.pyd from C:\opencv\build\python\2.7\ **x86** to C:\Python27\Lib\site-packages
I got this error when trying to import MySQLdb.
What worked for me was to uninstall Python and then reinstall it.
I got the error after installing npm (https://www.npmjs.com/get-npm). One thing it did was install Python even though I already had it.
First I copied cv2.pyd from /opencv/build/python/2.7/x86 to C:/Python27/Lib/site-packeges. The error was
"RuntimeError: module compiled against API version 9 but this version of numpy is 7"
Then I installed numpy-1.8.0-win32-superpack-python2.7.exe and OpenCV works fine.
>>> import cv2
>>> print cv2.__version__
2.4.13
Please make sure that you have installed a Python 2.7.12 or below version. Otherwise you will definitely get this error.
Make sure the Oracle client is 64 bit installed if the OS is 64 bit.
Make sure the Microsoft Visual C++ compiler for Python 2.7 is 64 for bit for a 64 bit OS or 32 bit for 32 bit.
Note: If your OS is 64 bit, install all packages of 64 bit or if the OS is 32 bit, install the 32-bit package.
This has worked for me. I have tried different methods, but this was my best solution.
Open a command prompt and type the following;
pip install opencv-python
(Make sure your Internet connection is on.)
After that, try importing it again.
It could also be that your Anaconda version is 32 bit when it should be 64 bit.
If you are using pycharm I go to settings -> python interpretation and click the + button and search for the name on the list of python packages there
An image showing where to go when you want to install something
I found the solution. Maybe you can try to use the cmd window rather than the Anaconda prompt window to start your first Scrapy test.
I'm using ubuntu x64, after two days and searching all the net, still i've not been able to install Megam,
i've read all information in this page http://www.cs.utah.edu/~hal/megam/
and installed x64 version of o'calm from http://packages.ubuntu.com/precise/ocaml
but when i want to use "megam" as a classifier in python, it says:
"NLTK was unable to find the megam file! Use software specific
configuration paramaters or set the MEGAM environment variable.
could anybody tell me how can i install and make use of it in python?
i've downloaded "ocaml-3.12.1.tar.gz" but the "make" command doesn't work (as it's said in its readme).
i've downloaded "megam_i686.opt" too, but it's not executable and i cannot run it
any help?
thanks in advance
For the future users:
megam is now available on MAC through brew:
$brew tap homebrew/science
$brew install megam
Use config_megam() to tell NLTK where the Megam executable is located. See: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.classify.megam-module.html for details and documentation.
You also need to build MEGAM with the right 32/64 bit setting for your system. "megam_i686.opt" is for x86 iirc, so you should compile it for 64 bit. It is a while since I did this, but a simple build on an x64 system was all I needed: "Make doesn't work" is not very useful: I'm sure it gave you a few error messages...? Probably paths not set or are read only?
Edit: Looks like the above link is currently broken. The main Megam site can be found at:
http://www.umiacs.umd.edu/~hal/megam/
although it hasn't been updated for a while.
Answer given by Hugh Perkins, helped me resolve the issue (due to low reputation can't add a comment to that answer). After downloading the zip file (from http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip), I needed to tell python where it was, and that was done by adding it in os.environ as:
os.environ["MEGAM"] = '<<Complete path followed by file name>>/megam-64'
I downloaded from http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip , which was linked from http://thinknook.com/nltk-megam-maximum-entropy-library-on-64-bit-linux-2012-11-27/ This worked ok for me, on ubuntu 14.04
I manged to get megam to run on my docker instance running debian 9.7 following the steps below. Based on steps for MacOS install steps suggested by Jack Hong here.
apt-get install make
apt-get install ocaml-nox (or apt-get install ocaml, if you want x window support)
download source from here
unzip source creating a megam_0.92 directory
Edit the Makefile in megam_0.92 and make the following changes. (The
first change was already done in my particular instance):
WITHCLIBS=-I /usr/local/lib/ocaml/caml
WITHSTR =str.cma -cclib -lcamlstr
Save the changes and run make inside your megam_0.92 directory
add nltk.config_megam('//megam_0.92/megam') to your script and all should be well.