简体   繁体   中英

Python: How to include the exe file of a script in setup.py

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 (ie 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 (ie 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM