Langdetect Issue With pyinstaller - python

I'm trying to compile my code in oython that uses the library langdetect into a .app with pyinstaller.
as answered in this question : https://github.com/pyinstaller/pyinstaller/issues/2680
I modified the .spec file to include this :
a = Analysis(
# your other stuff here...
datas=[
('langdetect/utils', 'langdetect/utils'), # for messages.properties file
('langdetect/profiles', 'langdetect/profiles'), # don't forget if you load langdetect as a submodule of your app, change the second string to the relative path from your parent module. The first argument is the relative path inside the pyinstaller bundle.
]
# the rest of your analysis spec...
)
But pyinstaller stil does not find utils. I think that I didn't enter the right path in the tuple, but I don't know what I'm supposed to do (the program is supposed to already 'be' in the libraries directory, so shouldn't it work in theory ?)
I used anaconda anaconda to install langdetect. The problem is that I'm not using my laptop to build the .app file, so I would refer if it's a generic path rather than specific.
thanks !

I had the same issue. The issue was with the langdetect library. I used textblob library instead and it worked perfectly.

Related

ZXing in python FileNotFoundError Problem

I have written a simple Python code to detect qrCode. Code:
import zxing
reader = zxing.BarCodeReader()
barcode = reader.decode('../images/QR_CODE-easy.png')
print(barcode)
Now, when I run it, I get the following error:
FileNotFoundError: [WinError 2] The system cannot find the file specified
I have check this file location is valid by using cv.imread command. Please let me know if someone has a solution to this problem.
You need to install Java Development Kit.
The readme of ZXing Python wrapper says the following:
Dependencies and installation
Use the Python 3 version of pip (usually invoked via pip3) to install: pip3 install zxing
You'll neeed to have a recent java binary somewhere in your path. (Tested with OpenJDK.)
pip will automatically download the relevant JAR files for the Java ZXing libraries (currently v3.4.1)
You appear to be on Windows (as the error code suggests), which uses the backslash for file paths.
It's not good practice as it won't be widely compatible, but if you're in a hurry and know you won't want to use the code on Mac or Linux, you can use double backslashes:
reader.decode('..\\images\\QR_CODE-easy.png')
Otherwise you should use os.path.join or pathlib (assuming your using Python 3)
import os.path
qr_file = os.path.join("..", "images", "QR_CODE-easy.png")
Or
from pathlib import Path
qr_file = Path("../images/QR_CODE-easy.png")
There are further details of a few options here:
https://medium.com/#ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f
Edit: it is also worth confirming that your relative path is indeed correct when starting in your current working directory. You can check the current working directory with: cwd = os.getcwd() . You may want to try an absolute path to your file too, just to confirm whether it works with that first.
More details on cwd here: https://stackoverflow.com/a/5137509/142780

Transferring Django from windows to ubuntu

I have written a project in windows with Django, It works well in windows, I wanted to transfer it to Ubuntu, first I installed the python3 and then made a virtualenv,
activated it and installed django and required packages, I got some errors but the main irritating one is that, I have a INI file, I use the configobj to read it, it works well in windows but in Ubuntu it give 'Key error' here is my code:
from configobj import ConfigObj
ConfigPath = os.path.join(settings.MEDIA_ROOT, 'Vars.ini')
ConfigParser = ConfigObj(ConfigPath)
print(ConfigParser['FileNames']['MotionName'])
and here is the file:
[FileNames]
MotionName = test1
I also tried to use only lowercase words but still no chance.
I can't believe it, my file was Vars.INI, windows would recognize it since it would take INI as extension but Ubuntu was looking for Vars.ini and it couldn't find it so I change the name from Vars.INI to Vars.ini.

Importing dependencies works in Pycahrm not Terminal?

I used below solution for importing dependencies.
I found this solution works if I run the code in Pycharm but not in Terminal.
The error message in Terminal is "cannot find graphics.primitive".
I'm using Mac and Python 3.5.
Why I see different behaviors from the Terminal and Pycharm?
How may I make the solution work for both?
http://chimera.labs.oreilly.com/books/1230000000393/ch10.html#_solution_169
Making a Hierarchical Package of Modules
Problem
You want to organize your code into a package consisting of a hierarchical collection of modules.
Solution
Making a package structure is simple. Just organize your code as you wish on the file-system and make sure that every directory defines an init.py file. For example:
graphics/
__init__.py
primitive/
__init__.py
line.py
fill.py
text.py
formats/
__init__.py
png.py
jpg.py
Once you have done this, you should be able to perform various import statements, such as the following:
import graphics.primitive.line
from graphics.primitive import line
import graphics.formats.jpg as jpg
You need to make sure that the graphics package is in the Python search path. PyCharm does this by extending sys.path as follows:
import sys
sys.path.extend(['/Users/hackworth/Development/graphics_parent_dir', '/Applications/PyCharm.app/Contents/helpers/pycharm', '/Applications/PyCharm.app/Contents/helpers/pydev'])
You can do the same in your code replacing /Users/hackworth/graphics_parent_dir with the appropriate path, or you can include the full path to graphics_parent_dir in the PYTHONPATH environment variable. See the Python documentation for details.
Another option would be to place the graphics package into a location the is searched by default on your system.

Create a python 3 exe with pyinstaller with Pmw module

Based on this Previos Post I'm trying to figure out how to make an exe out of my python files. The main issue seems to be that Pmw and its modules do not seem to import correctly though pyinstaller. The main error says:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\User\Name\AppData\Local\Temp\_MEI61522\Pmw
Looking at the Pmw init it seems what it's doing is looking for files in the directory which have Pmw_### and looking in there which has lib and then PmwLoader.suffix and loadther then imports all the dependencies
So now it seems pyinstaller isn't understanding this file dependency system created by Pmw and when I tried to follow the previous post instruction I ran into other errors that made the code unable to compile.
If anyone has any insight on this, that would be fantastic
PMW has a script for bundling (almost) everything into one file which I found in Lib\site-packages\Pmw\Pmw_\bin\bundlepmw.py
My version wasn't entirely Python 3 compliant so I had to make a few edits to the file before adding it to my sources.
Ugly but it worked for me.
Welp, I gave up on pyinstaller and downgraded to python 3.4 and used cx_freeze and created created a single Pmw.py file from some code which I found from python-pmw-and-cx-freeze

Create plugins for python standalone executables

how to create a good plugin engine for standalone executables created with pyInstaller, py2exe or similar tools?
I do not have experience with py2exe, but pyInstaller uses an import hook to import packages from it's compressed repository. Of course I am able to import dynamically another compressed repository created with pyInstaller and execute the code - this may be a simple plugin engine.
Problems appears when the plugin (this what is imported dynamically) uses a library that is not present in original repository (never imported). This is because import hook is for the original application and searches for packages in original repository - not the one imported later (plugin package repository).
Is there an easy way to solve this problem? Maybe there exist such engine?
When compiling to exe, your going to have this issue.
The only option I can think of to allow users access with thier plugins to use any python library is to include all libraries in the exe package.
It's probably a good idea to limit supported libraries to a subset, and list it in your documentation. Up to you.
I've only used py2exe.
In py2exe you can specify libraries that were not found in the search in the setup.py file.
Here's a sample:
from distutils.core import setup
import py2exe
setup (name = "script2compile",
console=['script2compile.pyw'],
version = "1.4",
author = "me",
author_email="somemail#me.com",
url="myurl.com",
windows = [{
"script":"script2compile.pyw",
"icon_resources":[(1,"./ICONS/app.ico")] # Icon file to use for display
}],
# put packages/libraries to include in the "packages" list
options = {"py2exe":{"packages": [ "pickle",
"csv",
"Tkconstants",
"Tkinter",
"tkFileDialog",
"pyexpat",
"xml.dom.minidom",
"win32pdh",
"win32pdhutil",
"win32api",
"win32con",
"subprocess",
]}}
)
import win32pdh
import win32pdhutil
import win32api
PyInstaller does have a plugin system for handling hidden imports, and ships with several of those already in. See the webpage (http://www.pyinstaller.org) which says:
The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. Check our compatibility list of SupportedPackages.

Categories