Найти - Пользователи
Полная версия: py2exe не получается "hello, world"
Начало » Python для новичков » py2exe не получается "hello, world"
1 2
axe
пробую скомпилировать код (файл 1.py):
# -*- coding: utf-8 -*-
print "hello"
с помощью скрипта:
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
setup(console=['1.py'])
файл 1.exe создаётся. пишет, что
Traceback (most recent call last):
File “C:\Python25\lib\site-packages\py2exe\boot_common.py”, line 92, in <module>
import linecache
File “linecache.pyc”, line 9, in <module>
File “os.pyc”, line 693, in <module>
File “copy_reg.pyc”, line 7, in <module>
File “types.pyc”, line 24, in <module>
File “inspect.pyc”, line 31, in <module>
File “string.pyc”, line 81, in <module>
File “re.pyc”, line 284, in <module>
AttributeError: ‘module’ object has no attribute ‘pickle’
добавил в файл boot_common.py строку import pickle, перекомпилировал.
получилась другая ошибка:

Traceback (most recent call last):
File “C:\Python25\lib\site-packages\py2exe\boot_common.py”, line 92, in <module>
import pickle
File “pickle.pyc”, line 29, in <module>
File “types.pyc”, line 24, in <module>
File “inspect.pyc”, line 31, in <module>
File “os.pyc”, line 693, in <module>
File “copy_reg.pyc”, line 7, in <module>
ImportError: cannot import name ClassType
в файле copy_reg.py на 7 строке:
from types import ClassType as _ClassType
igor.kaist
py2exe для 2.5 был скачен?
axe
py2exe-0.6.8.win32-py2.5.exe
igor.kaist
Стас, у тебя дар говорить не то… Перечитай тему, речь идет о py2exe, как это связано с pycompile?
pythonwin
Стас
Но на мой взгляд лучше использовать модуль
py_compile
дело в том что axe, нужен был файл типа exe что можно было запускать программу без установки питона на ПК пользователя, а py_compile.compile создает файлы pyc и pyo в байто коде, которые требуют установленного питона

>>> help(py_compile.compile)
Help on function compile in module py_compile:

compile(file, cfile=None, dfile=None, doraise=False)
Byte-compile one Python source file to Python bytecode.

Arguments:

file: source filename
cfile: target filename; defaults to source with ‘c’ or ‘o’ appended
('c' normally, ‘o’ in optimizing mode, giving .pyc or .pyo)
dfile: purported filename; defaults to source (this is the filename
that will show up in error messages)
doraise: flag indicating whether or not an exception should be
raised when a compile error is found. If an exception
occurs and this flag is set to False, a string
indicating the nature of the exception will be printed,
and the function will return to the caller. If an
exception occurs and this flag is set to True, a
PyCompileError exception will be raised.

Note that it isn't necessary to byte-compile Python modules for
execution efficiency – Python itself byte-compiles a module when
it is loaded, and if it can, writes out the bytecode to the
corresponding .pyc (or .pyo) file.

However, if a Python installation is shared between users, it is a
good idea to byte-compile all modules upon installation, since
other users may not be able to write in the source directories,
and thus they won't be able to write the .pyc/.pyo file, and then
they would be byte-compiling every module each time it is loaded.
This can slow down program start-up considerably.

See compileall.py for a script/module that uses this module to
byte-compile all installed files (or all files in selected
directories).
axe
Стас
тогда я думаю этом материал поможет
http://www.py2exe.org/index.cgi/Tutorial
у меня этот Tutorial, по сути, и не прокатывает.
axe
попробовал на другом компе запустить - скомпилировалось нормально. и консольное приложение, и GUI.
попробую завтра переустановить python.
pythonwin
axe
попробовал на другом компе запустить - скомпилировалось нормально. и консольное приложение, и GUI.
попробую завтра переустановить python.
похоже на шаманизм :(
Андрей Светлов
Да какой тут шаманизм?
Смотреть на site-packages, на easy_install.pth особенно внимательно смотреть….
Спросить __file__ у сопротивляющихся модулей - тоже помогает.
Сегодня камрад при установке пакета из 5 egg один кардинально перепутал - поставил совсем древний. Генерируемая ошибка на несколько секунд ввергла меня в ступор: никогда, никогда в жизни не видел таких имен для идентификаторов!!!
А оказалось - все совсем просто…
pythonwin
Андрей Светлов
Да какой тут шаманизм?
по небольшому собственному опыту - чаще всего переустановка без понимания причины проблемы/ошибки скорее всего приводит к той же проблеме, а если и проблема уходит после переустановки, то пользователь не может объяснить причину чтобы избежать проблемы в будущем и всё это сильно напоминает действия шамана = если и помогает, то причину объяснить не может и повторить результат сложно.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB