I'm trying to make an executable with this code(only for testing):
from panda3d.core import loadPrcFile
from direct.showbase.ShowBase import ShowBase
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
def main() -> None:
loadPrcFile('file.prc')
Game().run()
if __name__ == '__main__':
main()
when I try to make it up with pyinstaller I get this:
Warning: unable to auto-locate config files in directory named by "<auto>etc".
Don't use pyinstaller, Panda3D is configured for setuptools.
Create a requirements.txt file, in this file add: Panda3D
Than create a setup.py file, in this file add the following code:
from setuptools import setup
setup(
name="tester",
options = {
'build_apps': {
'include_patterns': [
'**/*.png',
'**/*.jpg',
'**/*.egg',
],
'gui_apps': {
'tester': 'main.py',
},
'log_append': False,
'plugins': [
'pandagl',
'p3openal_audio',
],
'platforms':['win_amd64']
}
}
)
Both files the requirements.txt and the setup.py should be in the folder where your Panda3D files are.
Don't forget to change tester: to_your_file_name.py in setup.py file.
Open a cmd window in the folder where the setup.py file is.
Run this command in your cmd:
python setup.py build_apps
This will create a windows 64 bit executable from yor Panda3D application in the build folder. There you will find the tester.exe file.
If you are using 3D models with textures, make sure they are also copied next to the executable file.
If you want to learn more check out the docs: https://docs.panda3d.org/1.10/python/distribution/index
Related
I'm trying to make with Python an EXE/MSI of my script, but in my script I use the library tkinter.tix i use that to create a Balloon tooltip. If i execute the script with the IDLE runs very well, but if i try to make an EXE(auto-py-to-exe) or MSI(cx_Freeze), shows me an error.
I import the module like this:
from tkinter.tix import *
I attach the error in picture.
I appreciate you can help me!!! Thanks...
You need to copy the tix folder in the Python installed folder into the distributed folder as well.
Below is a sample setup.py when cx_Freeze is used:
from cx_Freeze import setup, Executable
# change to the correct path for the tix folder in your system
include_files = [(r'C:\Python38\tcl\tix8.4.3', r'lib\tkinter\tix8.4.3')]
build_exe_options = {
'include_files': include_files,
}
bdist_msi_options = {}
setup(
name='Demo',
version='0.1',
options = {
'build_exe': build_exe_options,
'bdist_msi': bdist_msi_options,
},
executables=[Executable('tix-demo.py', base='Win32GUI')],
)
Then build the MSI by executing the following command:
python3 setup.py bdist_msi
In order to make pip or jupyter available from command-line on Windows no matter the current working directory with just pip ... or jupyter ..., Python on Windows seems to use this method:
put C:\Python37\Scripts in the PATH
create a small 100KB .exe file C:\Python37\Scripts\pip.exe or jupyter.exe that probably does not much more than calling a Python script with the interpreter (I guess?)
Then doing pip ... or jupyter ... in command-line works, no matter the current directory.
Question: how can I create a similar 100KB mycommand.exe that I could put in a directory which is in the PATH, so that I could do mycommand from anywhere in command-line?
Note: I'm not speaking about pyinstaller, cxfreeze, etc. (that I already know and have used before); I don't think these C:\Python37\Scripts\ exe files use this.
Assuming you are using setuptools to package this application, you need to create a console_scripts entry point as documented here:
https://packaging.python.org/guides/distributing-packages-using-setuptools/#console-scripts
For a single top-level module it could look like the following:
setup.py
#!/usr/bin/env python3
import setuptools
setuptools.setup(
py_modules=['my_top_level_module'],
entry_points={
'console_scripts': [
'mycommand = my_top_level_module:my_main_function',
],
},
# ...
name='MyProject',
version='1.0.0',
)
my_top_level_module.py
#!/usr/bin/env python3
def my_main_function():
print("Hi!")
if __name__ == '__main__':
my_main_function()
And then install it with a command such as:
path/to/pythonX.Y -m pip install path/to/MyProject
I have successfully converted .py file to .exe file using py2exe.
I can successfully run the .py file,if i run it standalone.However, when iam trying to run the .exe file, it throws an error as seen in attached image.
In my .py file, i have the below import statements:
import xlrd,xlwt,xlutils.copy,re,time,openpyxl,os
from openpyxl.styles import Alignment
from openpyxl import load_workbook
I have also accordingly tweaked setup.py file to include these packages as below setup.py code shows
from distutils.core import setup
import py2exe
setup(
console=['vu_t2.py'],
options = {
'py2exe': {
'packages': ['xlrd','xlwt','xlutils','openpyxl','openpyxl.workbook']
}
}
)
Please refer the attached error snapshot
I used the below command to run py2exe
python setup.py py2exe
openpyxl only supports distribution via pip.
I try to build my python selenium tests in exe file and run it on many machines for keeping tests independent of the environment. But result *.exe file can't find selenium webdriver. How can I include all selenium dependencies in *.exe file? Or maybe is there some another way for it?
Is it possible to make virtual environment and distribute it?
I am assuming you are using py2exe for generating exe. You will need to specify the location of selenium webdriver in the setup.py file.
Following code should help:
from distutils.core import setup
import py2exe
# Change the path in the following line for webdriver.xpi
data_files = [('selenium/webdriver/firefox', ['D:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]
setup(
name='General name of app',
version='1.0',
description='General description of app',
author='author name',
author_email='author email',
url='',
windows=[{'script': 'abc.py'}], # the main py file
data_files=data_files,
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
}
}
)
Like most other binary, it's probably required to include the DLL or whatever library you need, with the binary file. For example:
C:\tests\
run_tests.exe -- this will read from webdriver.dll
selenium-webdriver.dll
Also, from my .NET days i know that you were able to actually embed the library straight into the EXE, which makes it rather large.
You may try pyinstaller,it is simple to install and simple to use.
Install:
pip install pyinstaller
To exe:
pyinstaller yourprogram.py
This is old but I was looking for the same thing and I did have to dig in many different websites to find out my problem, so hopefully this will help others.
I was using py2exe to build my exe file but it didn't work so I decided trying pyinstaller and yeah, it worked.
Just gonna put the things in items to be more organized:
Py2exe:
I first started with py2exe and I was getting error like this:
python setup.py py2exe Invalid Syntax (asyncsupport.py, line 22)
I could fix it by deleting some of the things in the setup file, it looked like this in the end.
data_files = [('selenium/webdriver/chrome', ['C:\Python27\Lib\site-packages\selenium\webdriver\chrome\webdriver.py'])]
setup(
name='General name of app',
version='1.0',
description='General description of app',
author='author name',
author_email='author email',
url='',
windows=[{'script': 'final_headless.py'}], # the main py file
data_files=data_files,
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
'excludes': 'jinja2.asyncsupport',
'dll_excludes': ["MSVCP90.dll","HID.DLL", "w9xpopen.exe"]
}
}
)
It could run the py2exe but the exe file didn't work, then I moved to pyinstaller.
Pyinstaller:
For me pyinstaller look way easier than py2exe, so I am keeping with this from now. We only "problem" was that without the webdriver in the path the exe doesn't run.
But as soon as you have it in your variables path you are good to go.
Conclusion, using pyinstaller was my solution + adding webdriver to path.
I am trying to learn Python by myself using Zed A.Shaw's book Learn Python the hard way.
At exercise 46. I'am supposed to create a project skeleton (i.e. create a setup.py file, create modules, and so). Then make a project.
I have to put a script in my bin directory that is runnable for my system. I wrote the simple Hello World! script turned it into an .exe file using cxfreeze.
However when I try to install my setup.py file (i.e. By typing python setup.py install in the cmd), I can't install this .exe file instead I can only install the script script.py
How can I install this exe file.
This is my setup.py file:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
'description': 'First project',#ex46
'author': 'author',#
'url': '',#N/A
'download_url': '',#N/A
"author_email": "author_email#email.com"
'versio': '3.1',
'install_requires': ['nose'],
'packages': ['skeleton\quiz46','skeleton\\tests'],
'scripts': ['skeleton\\bin\helloscript.py','skeleton\\bin\helloscript.exe'],
'name': 'quiz46'
}
But this gives me the following error:
UnicodeDecodeError
I have also tried putting skeleton\bin\helloscript.exe but that gives me a similiar Error!
My OS is Windows 7, and I am using Python 3.1.
Again what I want is for the setup.py to install my .exe file too not just it's script.
I don't think the script option is meant to handle anything but text files. If you have a look at the source code for distribute (aka setuptools), the write_script command will try to encode('ascii') the contents if it's anything other than a python script AND if you are using Python 3. Your cxfreeze exe is a binary file, not a text file, and is likely causing this to choke.
The easier option to get setuptools to include a executable script in the installation process is to use the entry_points option in your setup.py rather than scripts:
entry_points={'console_scripts':['helloscript = helloscript:main'] }
The console_script will automatically wrap your original helloscript.py script and create an exe (on Windows) and install it into your Python's Script directory. No need to use something like cxfreeze.