I want to run a script on python that requires opencv-python. I'm working on a Mac. Based on other questions/answers here it seems the issue might be related to the M1 chip
I installed the latest version using the pip install command. Using pip list , I see that the installation was successful [opencv-python version 4.5.5]
now I encounter this error when I try to import cv2 on python3:
Traceback (most recent call last):
File "< stdin >", line 1, in < module >
ImportError: dlopen(/Users/maha/opt/anaconda3/lib/python3.9/site-packages/cv2.cpython-39-darwin.so, 0x0002): Library not loaded: #rpath/liblapack.3.dylib
Referenced from: /Users/maha/opt/anaconda3/lib/libopencv_core.4.5.5.dylib
Reason: tried: '/Users/maha/opt/anaconda3/lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/python3.9/site-packages/../../liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/python3.9/site-packages/../../liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/bin/../lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)
If I try to import on python (the older version) this is the error I get:
ImportError: No module named cv2
I tried to move the directory (opencv-python-4.6.0.66) to my anaconda3 library (where it looks like it is searching for it) with no success.. hope someone will be able to guide me
Related
I created an executable from a py file that used ttkwidgets
import tkinter as tk
import work_logger_database
from ttkwidgets.autocomplete import AutocompleteEntry
root = tk.Tk()
root.geometry('600x300')
items = work_logger_database.show_all()
stored_projects_list = list(set([items[i][2] for i in range(len(items))]))
#or:
#example_list = ['Hello', 'World']
project_entry = AutocompleteEntry(root, completevalues=stored_projects_list)
project_entry.grid(column=0, row=1, sticky='W')
root.mainloop()
and when I open the exe I get what is shown in this image
I also got a warning:
WARNING: Several hooks defined for module 'numpy'. Please take care they do not conflict.
I'm not sure if that's relevant
I tried a solution in creating the exe that didn't work:
pyinstaller work_logger.py --onefile -w --hidden-import=ttkwidgets --hidden-import=ttkwidgets.autocomplete
I also tried:
pyinstaller work_logger.py --onefile -w --hidden-import=ttkwidgets
Had the same ModuleNotFoundError: 'ttkwidgets' creating an executable of one of my scripts.
Worked after (re-)installing ttkwidgets on my system:
pip install ttkwidgets
I am running a virtual environment with Python 2.7 for my program.
There seems to be a problem after creating the executable file on windows.
I ran venv/Scripts/pyinstaller.exe -F main.py
everything seems fine. But when i click on the created executable main.exe.
There is an error.
Tried and tested
I have re-installed of pandas and pyinstaller
Implemented the hook-pandas.py to the hooks folder in the environment.
hook-pandas
Ensured the environment is activated.
Checked that the program is running fine before building executable.
Re-created the environment.
Yet after all that, I am prompted with this issue [see Importerror] when I run the executable file.
It is an extreme pain to debug this because the command prompt displaying the error will not pause but close almost immediately.
Similar issues
Looking for Suggestions
I am hoping for suggestions to troubleshoot Pyinstaller. Any resources to read up on would be nice.
Usually, I have no trouble with python as Pycharm has several handy debugging tools that will help me identify the problem
I ran into the same problem and found this thread, but I managed to solve it borrowing from the reference you posted (about pandas._libs.tslibs.timedeltas), so thank you for that!
In that article, the module that resulted in the ImportError was, in fact pandas._libs.tslibs.timedeltas, if you look at the poster's logs. But the error you and I ran into refers to np_datetime instead. So, from the traceback logs, I finally figured out that the code we have to write in hook-pandas.py should be the following:
hiddenimports = ['pandas._libs.tslibs.np_datetime']
Maybe that alone will solve your problem, HOWEVER, in my case, once I solved the np_datetime issue, other very similar ImportError problems arose (also related to hiddenimports regarding pandas), so, in case you run into the same issues, just define hiddenimports as follows:
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
TL;DR:
You can first try to write
hiddenimports = ['pandas._libs.tslibs.np_datetime']
into hook-pandas.py. However, if for some reason you run into the exact same issues I did afterwards, try
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
If you wish to dive deeper (or run into a different pandas ImportError than the ones I did), this is the code in pandas's __init__.py referenced in your traceback log (lines 23 to 35):
from pandas.compat.numpy import *
try:
from pandas._libs import (hashtable as _hashtable,
lib as _lib,
tslib as _tslib)
except ImportError as e: # pragma: no cover
# hack but overkill to use re
module = str(e).replace('cannot import name ', '')
raise ImportError("C extension: {0} not built. If you want to import "
"pandas from the source directory, you may need to run "
"'python setup.py build_ext --inplace --force' to build "
"the C extensions first.".format(module))
From that I went into the
C:\Python27\Lib\site-packages\pandas_libs
and
C:\Python27\Lib\site-packages\pandas_libs\tslibs
folders and found the exact names of the modules that resulted the errors.
I hope that solves your problem as it did mine.
Cheers!
I have a local spark 1.5.2 (hadoop 2.4) installation on Windows as explained here.
I'm trying to import a jar file that I created in Java using maven (the jar is jmatrw that I uploaded on here on github). Note the jar does not include a spark program and it has no dependencies to spark. I tried the following steps, but no one seems to work in my installation:
I copied the library in "E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar"
Edit spark-env.sh and add SPARK_CLASSPATH="E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar"
In a command window I run > spark-shell --jars "E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar", but it says "Warning: skip remote jar"
In the spark shell I tried to do scala> sc.addJar("E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar"), it says "INFO: added jar ... with timestamp"
When I type scala> import it.prz.jmatrw.JMATData, spark-shell replies with error: not found: value it.
I spent lot of time searching on Stackoverflow and on Google, indeed a similar Stakoverflow question is here, but I'm still not able to import my custom jar.
Thanks
There are two settings in 1.5.2 to reference an external jar. You can add it for the driver or for the executor(s).
I'm doing this by adding settings to the spark-defaults.conf, but you can set these at spark-shell or in SparkConf.
spark.driver.extraClassPath /path/to/jar/*
spark.executor.extraClassPath /path/to/jar/*
I don't see anything really wrong with the way you are doing it, but you could try the conf approach above, or setting these using SparkConf
val conf = new SparkConf()
conf.set("spark.driver.extraClassPath", "/path/to/jar/*")
val sc = new SparkContext(conf)
In general, I haven't enjoyed working with Spark on Windows. Try to get onto Unix/Linux.
On "./configure" of an open source project I get:
user agent OS = Linux
./configure: line 13957: syntax error near unexpected token 0.9.3'
./configure: line 13957: GOBJECT_INTROSPECTION_CHECK(0.9.3)'
make: *** [config.status] Error 2
Ubuntu 12.04 package "gobject-introspection" and "libgirepository1.0-dev" are present. Removing the GOBJECT_INTROSPECTION_CHECK line allows configure to complete, but the project fails a dependency later.
How can I get past this configure step cleanly? Googling for this issue shows bugs filed against numerous OS projects for this same blocking issue, but the usual answer is "install gobject-introspection".
As the OP discovered on his own he had to install the gobject-introspection package to get the m4 macros that were being used.
The error message has the raw macro in it, as configure scripts are generated from configure.in/configure.ac files via m4/etc the fact that the raw macro is in the output file indicates that the macro did not get translated at generation time.
The gobject-introspection m4 files were apparently installed after autogen.sh (or equivalent) was run to generate the configure script. Re-running the autogen.sh script should regenerate the configure script and run the macro correctly.
The error occurs also when using zopeskel in Plone 4.3.3. This seem to be slightly different from this question. Under Plone 4.3.2 there is no error.
$ ../bin/paster create plone_basic
Selected and implied templates:
PasteScript#basic_package A basic setuptools-enabled package
Variables:
egg: plone_basic
package: plone_basic
project: plone_basic
Enter version (Version (like 0.1)) ['']:
Enter description (One-line description of the package) ['']:
Enter long_description (Multi-line description (in reST)) ['']:
Enter keywords (Space-separated keywords/tags) ['']:
Enter author (Author name) ['']:
Enter author_email (Author email) ['']:
Enter url (URL of homepage) ['']:
Enter license_name (License name) ['']:
Enter zip_safe (True/False: if the package can be distributed as a .zip file) [False]:
Creating template basic_package
Creating directory ./plone_basic
Recursing into +package+
Creating ./plone_basic/plone_basic/
Copying __init__.py to ./plone_basic/plone_basic/__init__.py
Copying setup.cfg to ./plone_basic/setup.cfg
Copying setup.py_tmpl to ./plone_basic/setup.py
Running /home/Plone-4.3.3/Python-2.7/bin/python setup.py egg_info
Traceback (most recent call last):
File "/home/Plone-4.3.3/zeocluster/bin/paster", line 259, in <module>
sys.exit(paste.script.command.run())
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 104, in run
invoke(command, command_name, options, args[1:])
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 143, in invoke
exit_code = runner.run(args)
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 238, in run
result = self.command()
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/create_distro.py", line 170, in command
egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name)
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/pluginlib.py", line 135, in egg_info_dir
% ', '.join(all))
IOError: No egg-info directory found (looked in ./plone_basic/./plone_basic.egg-info, ./plone_basic/setup.py/plone_basic.egg-info, ./plone_basic/plone_basic/plone_basic.egg-info, ./plone_basic/setup.cfg/plone_basic.egg-info)
workaround 1:
The problem seems to be the missing setuptools. After installing setuptools, then paster (and all tools based on it) can run the generated setup.py. The following fixed the problem:
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | sudo -u plone_buildout /usr/local/Plone-4.3.3/Python-2.7/bin/python
UnifiedInstaller-4.3.3 doesn't install setuptools. See this ticket.
As SteveM points out (see comments) this is not a recommended workaround.
(prefered) workaround 2:
The generated data is there (despite the thrown error!) but setup.py will not run. Thus the Paste* directories will not be generated. Later when buildout runs it will generate/download the Paste* directories etc.
If you want setup.py to be run. You could patch PasteScript (at your own risk!).
As for PasteScript-1.7.5 go to line #587 of /path/to/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py and get the current sys.path and pass it to subprocess.Popen(). This way the setup.py will run with the zopeskel or paste environment.
current_env = os.environ.copy()
current_env['PYTHONPATH'] = ':'.join(sys.path)
proc = subprocess.Popen([cmd] + list(args),
cwd=cwd,
stderr=stderr_pipe,
stdout=subprocess.PIPE,
env=current_env) # <- pass the env here
I'll try to figure out situations where this workaround could cause problems. I've posted an issue on PasteScript: https://bitbucket.org/ianb/pastescript/issue/16/pass-the-syspath-to-the-subprocess-in
Update: without generating/adding the Paste* dirs (either running buildout or by workaround as above) localcommands won't be available.