Py2exe enchant error - py2exe

Hi i compiled my python script that includes enchant and when i try to execute my program i get the following error
ImportError: The 'enchant' C library was not found. Please install it via your OS package manager, or use a pre-built binary wheel from PyPI.
I run 64bit Windows.
My setup.py file looks like this
from distutils.core import setup
from glob import glob
from PyQt4 import QtCore, QtGui
import numpy as np
import sys
import os, os.path
import time
import exifread
import logging
import re
import datetime
import hashlib
import sqlite3
import MySQLdb as msql
import jsbeautifier
import enchant
import sys
import py2exe
import six
Mydata_files = []
for files in os.listdir('C:\\Users\\agis\\Dropbox\\PyWall\\Files'):
f1 = 'C:\\Users\\agis\\Dropbox\\PyWall\\Files\\' + files
if os.path.isfile(f1): # skip directories
f2 = 'Files', [f1]
Mydata_files.append(f2)
sys.path.append('C:\\Windows\\WinSxS\\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_e163563597edeada')
sys.path.append("C:\\Python27\\Lib\\site-packages")
setup(windows=['pywall.py'],
data_files = Mydata_files)
If i remove enchant from my script the executable run perfect.How i can include enchant to my exe.

Please see the documentation http://pythonhosted.org/pyenchant/tutorial.html#packaging-pyenchant-with-py2exe
"PyEnchant depends on a large number of auxilliary files such as plugin libraries, dictionary files, etc. While py2exe does an excellent job of detecting static file dependencies, it cannot detect these files which are located at runtime.
To successfully package an application that uses PyEnchant, these auxilliary files must be explicitly included in the “data_files” argument to the setup function. The function enchant.utils.win32_data_files returns a list of files which can be used for this purpose."

For this issue:----> Py2exe enchant error.
You can use the alternative solution, by downloading "language_check 2.x" which can be used to check the grammatical mistakes of your English. Also, can be used in Py2 & Py3.
https://pypi.org/project/language-check/

Related

Get and install requirements.txt for python file into virtualenv

I have the following packages I need to install into my virtual environment for an app deployment. This is how they read at the top of my app's file:
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta, date
from dateutil.relativedelta import relativedelta
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from scipy import stats
from sklearn import metrics
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
import statsmodels.api as sm
I'm not sure how to install the ones that say "from x import y, z". I'd also much prefer to do something more global(?) than install each thing one by one into the virtualenv.
As I understand it, the pip freeze > requirements.txt command only generates a requirements file based on what's manually been installed into the virtualenv. I'd rather get something together that looks at my app file and generates a requirements.txt based on that, and then install the contents of the requirements.txt into the virtualenv directly, as opposed to installing each package one by one.
from foo import bar is essentially equivalent to:
import foo
bar = foo.bar
It just imports the module then loads some of its variables into scope. So, from scipy import stats would be in the scipy module. As for automatically generating a requirements.txt, this is what pipreqs is made for.
I installed pipreqs and then used
pipreqs .
from command line while in the directory of the folder with the app in it. This generated a requirements.txt with all the proper packages. Still working on installing the requirements.txt into the virtualenv, but thats been answered many times elsewhere.
EDIT: install requirements.txt into virtualenv using:
pip install -r requirements.txt

Tensorflow .so issues Mac OS X

I am having trouble getting the Tensorflow example to progress beyond the first line of code beyond my imports. With no other errors, I receive the following:
NotFoundError: dlopen(/Users/opusandcaymus/Election/word2vec_ops.so, 6): image not found
I have a dedicated Tensorflow environment in Anaconda 4.0.1 running Python 3.5. Tensorflow was freshly installed in that environment as version 1.4.1. I'm not sure what the .os file does for word2vec, but Google's example problem requires this line (Google Example Link). Thanks in advance.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
import threading
import time
from six.moves import xrange # pylint: disable=redefined-builtin
import numpy as np
import tensorflow as tf
word2vec = tf.load_op_library(os.path.join(os.path.dirname(os.path.realpath("__file__")), 'word2vec_ops.so'))

Cython cython.parallel unrecognized import

I am trying to use parallelism in cython. I am not able to import the cython module 'parallel'.
I have tried the following variations to no avail:
from cython import parallel
import cython.parallel
cimport cython.parallel
from cython.parallel cimport prange
from cython.parallel import prange
At the top of a .pyx file. Nothing else is included in the file so far. I get red underlines for the first line's "parallel" and the last and second last line's "prange" with unresolved references. I am using cython version 0.27.
When typing the import statement
import cython.pa___________
once i type ".pa" the suggestions are "cython.set_initial_path, cython.test_assert_path_exists, cython.test_fail_if_path_exists, cython.wraparound". I am using Intellij PyCharm professional edition.
Other parallel code has the following usually at the top of their code:
from cython.parallel import prange
which does not seem to work or exist for me. Does anyone know what I am missing?
The correct incantation is from cython.parallel import prange. Note that you are editing a cython file, not a python file. PyCharm is pointing out issues that would be a problem if this were a python file.

Pyinstaller: ImportError: cannot import name QtGui

Using the latest pyinstaller on Windows 7 to make a standalone exe (-F), when running the exe:
ImportError: cannot import name QtGui
In the pyinstaller hooks directory there is special handling for PyQt4 though not PySide.
Hoping for a workaround for this or something to try.
Environment
Windows 7 64-bit
Python 2.7 32-bit
PYTHONHOME=c:\python27
PYTHONPATH=c:\python27\lib
PYTHONLIB=c:\python27\libs\python27.lib;c:\python27\lib\site-packages
Steps
1. Add PySide from http://releases.qt-project.org/pyside/1.1.1/PySide-1.1.1qt474.win32-py2.7.exe
2. Unzip https://github.com/pyinstaller/pyinstaller/zipball/develop to c:\pyinstaller1.5.1
3. Run the commands below against a .py file containing simply:
from PySide import QtGui
[...or QtCore or or.]
Run
c:\pyinstaller1.5.1>pyinstaller.py -F import_test.py
108 INFO: wrote c:\pyinstaller1.5.1\import_test.spec
171 INFO: Testing for ability to set icons, version resources...
296 INFO: ... resource update available
312 INFO: UPX is not available.
4321 INFO: checking Analysis
4382 INFO: checking PYZ
4430 INFO: checking PKG
4446 INFO: building because c:\pyinstaller1.5.1\build\pyi.win32\import_test\import_test.exe.manifest changed
4446 INFO: building PKG out00-PKG.pkg
16782 INFO: checking EXE
16782 INFO: rebuilding out00-EXE.toc because pkg is more recent
16782 INFO: building EXE from out00-EXE.toc
16799 INFO: Appending archive to EXE c:\pyinstaller1.5.1\dist\import_test.exe
c:\pyinstaller1.5.1>dist\import_test.exe
Traceback (most recent call last):
File "<string>", line 23, in <module>
ImportError: cannot import name QtGui
Note
At the end of the PySide install (as admin), this message:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
If that is about post install it can be handled manually:
c:>python.exe c:\Python27\Scripts\pyside_postinstall.py -install
Generating file C:\python27\qt.conf...
PySide installed in c:/python27/Lib/site-packages/PySide...
The PySide extensions were successfully installed.
Workaround. This worked:
# Various imports, whatever, using normal sys.path, for example:
import os, sys, re, time, random
import subprocess, psutil
# Save sys.path
sys_path_saved = sys.path
# Limit sys.path for PySide import
sys.path = ['c:\\python27\\lib\\site-packages']
# PySide imports with limited sys.path
from PySide import QtGui, QtCore
from PySide.QtGui import QApplication, QLineEdit
from PySide.QtCore import QSettings, Qt
# Reset sys.path to original
sys.path = sys_path_saved
# Remainder of code...
Pyinstaller 1.5.1 should do a fine job of locating dependencies, and often does.
However, all of many many attempts to use its pathex or hiddenimports in .spec failed.
Modifying my environment variables also failed.
Extracting various module files manually from from .egg sometimes worked.
However for PySide imports, the sys.path temporary limitation above was the workaround that worked.
Update: Unfortunately the exe only works on a machine with Python/Pyside installed, doesn't work on XP without Python.
For me what worked straight away was to copy/paste the two folders PySide6 and shiboken6 from my python installation folder (PYTHON_FOLDER/Lib/site-packages) to the dist/APP_NAME folder resulting from pyinstaller SCRIPT_NAME.

IPython fails to load win32api

I'm running Python 2.7 on windows and I've installed the pywin extension here.
Having done so, if I launch a normal python shell, I can import win32api perfectly.
If I do the same on IPython, I get this :
In [1]: import win32api
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Windows\system32\<ipython console> in <module>()
ImportError: DLL load failed: The specified module could not be found.
In [2]:
Why would it work in a normal python shell, but not IPython?
I had the same issue, and found a solution for my problem here. Apparently it's a conflict between pythoncom24.dll and pywintypes24.dll.
Look in your root Python install folder. If you find these two DLLs there, move them to \Python24\Lib\site-packages\win32 instead. This should fix your import conflict.
Alternately, you can control the imports explicitly. Add the following to your script in this order:
import pywintypes
import pythoncom
import win32api

Resources