Python GUI2Exe Application Standalone Build (Using Py2Exe) - python

I am trying to build a Python Script into a stand alone application. I am using GUI2Exe. My script uses selenium package. I have it installed.
Project compiles fine and runs on python command line directly but fails to build a stand alone because it is referring to folder:
ERROR: test_file_data_extract (__main__.FileDataExtract)
----------------------------------------------------------------------
Traceback (most recent call last):
File "File_data_extract.py", line 18, in setUp
File "selenium\webdriver\firefox\firefox_profile.pyc", line 63, in __init__
IOError: [Errno 2] No such file or directory: 'C:\\users\\username\\PycharmProjects\\Python_27_32bit\\file_data_extract\\dist\\File_data_extract.exe\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
It is looking for selenium package is located at :
C:\Users\username\Anaconda2_Py27_32bit\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\firefox
where C:\Users\username\Anaconda2_Py27_32bit is where I installed Anaconda Python 2.7, 32 bit version. By default it is looking for in \dist\filename.exe folder.

I was able to build it using bbfreeze. It works great.
First I had to install bbfreezee via pip (one time only):
pip install bbfreeze
Create a build_package.py file as:
from bbfreeze import Freezer
f = Freezer("project_name", includes=("selenium","SendKeys",)) #list problem packages here to manually include
f.addScript("project_name_script.py")
f() # starts the freezing process
Build project:
python build_package.py bdist_bbfreezee
in folder project_name where project_name_script.py sits you find project_name_script.exe with all the include packages including selenium and sendkeys. When you distribute the package you need to distribute entire project_name because it contains all dependent library dlls (python .pyd).
More details refer official bbfreezee here:
https://pypi.python.org/pypi/bbfreeze/#downloads

Related

Determining the issue regarding python versions for running repo init

When I am using repo init to initialize some repo from a source, I keep getting:
Traceback (most recent call last):
File "/home/workspace/.repo/repo/main.py", line 56, in <module>
from subcmds.version import Version
File "/home/workspace/.repo/repo/subcmds/__init__.py", line 38, in <module>
['%s' % name])
File "/home/workspace/.repo/repo/subcmds/upload.py", line 27, in <module>
from hooks import RepoHook
File "/home/workspace/.repo/repo/hooks.py", line 472
file=sys.stderr)
^
SyntaxError: invalid syntax
The following are the python versions I have:
python -V -> 2.7
python3 -V -> 3.6
According to this link, python 3.6 is required starting with repo-1.14 but I'm not certain if that's what my repo version is - didn't have any luck finding a way around determining the version.
Looks like you are running an old repo launcher script version that is incompatible with the latest repo version. To fix this, download the latest repo launcher python script from Google and replace your outdated one.
The launcher script is the executable python script called "repo" and is located in your PATH, usually ~/bin (according to Google's instructions) or ~/.local/bin/. To find out where yours is located, type which repo in the terminal and it will print the script's location.
Let's say your repo script is in ~/bin. To download the script (and make it executable), you can do:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Also, you do not need to remove Python 2.7 for repo to work. I use Ubuntu 18.04 and have both Python 2.7 and 3.6 installed as well, and repo runs fine.

Pyinstaller create an executable with external libraries

I am trying to create an executable file (exe) for a Python script that I written in PyCharm.
When I run the script from the PyCharm is working fine but when I try to run it as an individual .py or try to run the exe I am getting an error.
The issue I believe is with the "from infi.devicemanager import DeviceManager" library.
from infi.devicemanager import DeviceManager # Used for the retrievement of Device manager information
dm = DeviceManager()
dm.root.rescan()
devs = dm.all_devices # Get all the devices to a list called devs
for d in devs:
print (d.description)
I get following error:
PS C:\Python> python.exe .\tests.py
Traceback (most recent call last):
File ".\tests.py", line 1, in <module>
import infi.devicemanager # Used for the retrievement of Device manager information
ModuleNotFoundError: No module named 'infi'
PS C:\Python> pyinstaller -F .\tests.py
PS C:\Python\dist> .\tests.exe
Traceback (most recent call last):
File "tests.py", line 1, in <module>
ModuleNotFoundError: No module named 'infi'
[15072] Failed to execute script tests
Is there a way to include this library to the exe file so anyone without python can run this script?
I am open to suggestions.
Thank you in advance!
=== UPDATE ===
Full script can be found here
https://github.com/elessargr/k9-serial
My answer assumes that the interpreter that has infi.devicemanager is C:\Python\venv\Scripts\python.exe as stated by OP in the comments
So there is virtual environment named venv. You need to activate the virtual environment and install PyInstaller in it.
C:\Python>venv\Scripts\activate
(venv)C:\Python>
Note (venv) in front of your shell - that means virtual environment venv is activated
Now install PyInstaller
(venv)C:\Python>pip install pyinstaller
-- here it will install pyinstaller --
now you can test that both pyinstaller and infi.devicemanager are installed in venv
(venv)C:\Python>pip list
it should list both packages among some others. now
(venv)C:\Python>pyinstaller -F C:\Python\tests.py --hidden-import=infi.devicemanager
--here it will create the exe --
if I was right it should work now
EDIT: It looks like infi is using __import__(pkg_resources), so the command should be
(venv)C:\Python>pyinstaller -F C:\Python\tests.py --hidden-import=infi.devicemanager --hiden-import=pkg_resources

How to alter setup.py for CyIPOPT

I want to install the python package CyIpopt (https://github.com/matthias-k/cyipopt) on windows 10 and python version 3.5.2. For the binary I am using http://www.coin-or.org/Binaries/Ipopt/Ipopt-3.10.1-Win32-Win64-dll.7z (which I unpacked). The github page gives install instructions. At one point it says:
Download the source files of cyipopt and update setup.py to point to the header files and binaries of the Ipopt package, if LD_LIBRARY_PATH and pkg_config are not setup to find ipopt on their own.
I downloaded the source files from github and edited the setup.py file by altering lines 33-36 to :
IPOPT_ICLUDE_DIRS=['D:\...\Ipopt-3.10.1-Win32-Win64-dll\include\coin', np.get_include()]
IPOPT_LIBS=['IpOptFSS','IpOpt-vc10','IpOpt-vc8']
IPOPT_LIB_DIRS=['D:\...\Ipopt-3.10.1-Win32-Win64-dll\lib\\x64\Release MKL']
IPOPT_DLL=['IpOptFSS.dll','IpOpt-vc10.dll','IpOpt-vc8.dll']
The dots represent the path to these folders on my computer. Now when I run python setup.py install, it run succesfuly. However when I then run python and import ipopt I get the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Linthorst\Miniconda3\lib\site-packages\ipopt-0.1.6-py3.5-win-amd64.egg\ipopt__init__.py", line 40, in
from cyipopt import *
ImportError: No module named 'cyipopt'
I suspect I altered the setup.py file incorrectly (since I made an educated guess). I am confused that it installed but doesn't work. Can anybody help me solve this error? Many thanks in advance

Cannot import distutils from within a py2exe-compiled script

I am on Windows Server 2012R2, trying to compile a script with py2exe, within a virtualenv, and I'm getting issues whenever one of the application scripts tries to "import distutils" (in my case, it's somewhere inside a 3rd-party library, but I reduced the problem here).
Steps to reproduce:
Create a virtualenv
virtualenv venv
call venv\Scripts\activate
Install py2exe inside the virtualenv
easy_install --always-unzip py2exe-0.6.9.win64-py2.7.amd64.exe
Create setup.py
from distutils.core import setup
try:
import py2exe
except:
pass
setup(
console=[
'py2exe_distutils.py'
]
)
Create py2exe_distutils.py
import distutils
Run py2exe
python setup.py py2exe
Try to run the generated executable
dist\py2exe_distutils.exe
It returns:
C:\Users\root\p\dist\library.zip\distutils\__init__.py:14: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
File "py2exe_distutils.py", line 6, in <module>
import distutils
File "distutils\__init__.pyc", line 25, in <module>
ImportError: cannot import name dist
The script runs fine when I run it directly (python py2exe_distutils.py), even from within the virtualenv.
Am I trying to do something unsupported by py2exe, or is something wrong with my setup?
I had the same problem while creating an executable that used pandas 0.12.0. This worked for me: before you create the executable, copy the distutils folder from the base python installation
robocopy C:\Python27\Lib\distutils venv\Lib\distutils /E /COPY:DAT
I am using virtualenv 12.0.4 and py2exe 0.6.6 on Windows 7 Professional. Some extra insight can be found here. This answer pointed me in the direction of just copying the files.

Python bindings for libtorrent-rasterbar are not working

I'm running Debian 6.0.6
I've downloaded latest version of libtorrent-rasterbar from here: http://code.google.com/p/libtorrent/downloads/detail?name=libtorrent-rasterbar-0.16.6.tar.gz&can=2 and installed it:
./configure --enable-python-binding
make
make install
cd bindings/python
python setup.py build
python setup.py install
now I want to test whether the library works:
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libtorrent-rasterbar.so.7: cannot open shared object file: No such file or directory
The packaged version of libtorrent from the distributive's repository had some funny behaviour (complaining on boost dependences), so I've decided to upgrade. The same situation is on both of my debian boxes, yet ubuntu box is fine.
old error message from my debian box:
File "ar.py", line 15, in create
s.start_dht()
Boost.Python.ArgumentError: Python argument types in
session.start_dht(session)
did not match C++ signature:
start_dht(libtorrent::session {lvalue}, libtorrent::entry)
Search for the shared object file and add it to your path.
sudo updatedb
locate libtorrent-rasterbar.so.7
This should output /<path_to_directory>/libtorrent-rasterbar.so.7
Add this to your ~/.profile or temporarily tell Python where to look:
export LD_LIBRARY_PATH=/<path_to_directory>/
See more detailed installation instructions here.

Categories

Resources