ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Problems with py2exe
Posted by Sean on Nov-21-2013 04:53
I am attempting to compile my python project into an exe using py2exe.  Unfortunately, I am receiving the error: ImportError: No module name pychartdir27".  I am using 32-bit Python 2.7 and 32-bit Chart Director.  Is there a fix for this error?  Maybe adding/changing something in my py2exe setup.py file?

  Re: Problems with py2exe
Posted by Peter Kwan on Nov-22-2013 03:09
Hi Sean,

I assume your Python project works normally in Python. But when you try to "compile" it using py2exe, it fails to produce a workable executable. I suspect the issue is not caused by ChartDirector. As py2exe is unable to produce an EXE from some code that surely is correct and working, it can be a configuration issue of py2exe. You may consider to contact py2exe support.

My guess is, if the "ImportError" occurs when py2exe is building the executable, it may be because py2exe does not know where is "pychartdir27.pyd". If the "ImportError" occurs when you try to run the compiled executable, may be py2exe has not included ChartDirector in the executable. In this case, you may want to configure py2exe to included the ChartDirector pyd and dll when compiling the code. Another possibility is that py2exe has included pychartdir27.pyd in the executable, but does not know how to extract it so that the Python interpreter can find it. So the Python interpreter complains that it cannot find the file.

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by Sean on Nov-22-2013 04:30
Peter,

I was able to solve my issue by including the pychartdir27.pyd in my setup.py file for py2exe.  Executable builds and runs perfectly.  Quick fix.  Thank you for the help.

  Re: Problems with py2exe
Posted by taylor on Jan-15-2014 12:26
Hi,Sean
I also met the same problem.
Could you please list your code that how to include it in setup.py.
Sean wrote:

Peter,

I was able to solve my issue by including the pychartdir27.pyd in my setup.py file for py2exe.  Executable builds and runs perfectly.  Quick fix.  Thank you for the help.

  Re: Problems with py2exe
Posted by Peter Kwan on Jan-16-2014 05:35
Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by taylor on Jan-26-2014 23:07
Hi Peter,
  I have try it,but not work. There are two errors. One is "_sysconfigdata" module missing, and another were the same as before。

Traceback (most recent call last):
  File "ChartTest.py", line 6, in <module>
  File "pychartdir.pyo", line 5, in <module>
ImportError: No module named pychartdir27
Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

Peter Kwan wrote:

Hi taylor,

I have never used py2exe before. Anyway, I folloed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by Peter Kwan on Jan-16-2014 05:35
Hi taylor,

I have never used py2exe before. Anyway, I followed Sean's instruction and found that the
following setup.py file seems to work:


from distutils.core import setup
import py2exe

setup(
console=['simplebar.py'],
options={"py2exe": {"includes": ["pychartdir27"]}},
data_files=['chartdir.dll']
)

(Note: The above is for python 2.7, and it assumes the pychartdir27.pyd and chartdir.dll is
in the same directory as the script. Please modify the above to suit your Python version and
directory structure.)

Hope this can help.

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by Peter Kwan on Jan-28-2014 04:00
Hi taylor,

The followings are exactly what I have done:

(a) Download Python 2.7 and install it in a newly installed Windows 7 computer.

(b) Download py2exe and install it in the sample computer.

(c) Download ChartDirector for Python and unzip it in c:\\ChartDirector

(d) Copy all files from "c:\\ChartDirector\\lib" to "c:\\ChartDirect\\pythondemo"

(e) Open a command shell, "cd \\ChartDirector\\pythondemo". You should be able to run
the command "python simplebar.py" normally.

(f) Create the setup.py as mentioned in my last message and put it in
"c:\\ChartDirect\\pythondemo".

(g) Run "python setup.py py2exe"


In your case, please try to use my setup.py first (which uses "simplebar.py", not
"ChartTest.py"). This is just to test if it works with ChartDirector. The "ImportError: No
module named pychartdir27" you see is because py2exe cannot find the "pychartdir27".
To find this file, the file needs to be in a place that py2exe will search for. I am not sure
which place py2exe will search for. In my testing, I found that putting all the files in the
same directory as the script and also running the py2exe using a command shell in that
directory works.

I noted that in the error message, it mentions about "pychartdir.pyo". I am not sure what
is "pychartdir.pyo" as ChartDirector does not have this file. Is this file created by you or
is it automatically inferred to by py2exe? The standard method to import ChartDirector is
"from pychartdir import *" or "import pychartdir"

The error about "_sysconfigdata" should be unrelated to ChartDirector. From my
understanding, it is a standard Python module, and is possibly used by "distutils.core",
which is also a standard Python module. According to the official py2exe web site, the
first line of setup.py should be "from distutils.core import setup". Is it possible you have
more than one Python version in your computer? Sometimes mixing Python versions may
cause similar issues.


Regards
Peter Kwan

  Re: Problems with py2exe
Posted by taylor on Feb-08-2014 12:10
Hi Peter,
   Thank you for your detail reply.
I have try it using the following setup.py to get the simplebar.exe file, but after i run it,the result were the same, and i found that there is no pychartdir27.pyd in the dist directory even copy it into still not work.


#!/usr/bin/evn python
# -*- coding: utf-8 -*-
# setup.py
from distutils.core import setup
import py2exe
setup(console=['ChartTest.py'],options={"py2exe": {"includes": ["pychartdir27"]}},data_files=['chartdir.dll'])


C:\\ChartDirector\\pythondemo\\dist>dir/w
[.]                   [..]                  bz2.pyd
chartdir.dll          library.zip           python27.dll
pythoncom27.dll       pywintypes27.dll      select.pyd
simplebar.exe         unicodedata.pyd       w9xpopen.exe
win32api.pyd          _hashlib.pyd          _win32sysloader.pyd

C:\\ChartDirector\\pythondemo\\dist>simplebar
Traceback (most recent call last):
  File "simplebar.py", line 2, in <module>
  File "pychartdir.pyc", line 5, in <module>
ImportError: No module named pychartdir27
Peter Kwan wrote:

Hi taylor,

The followings are exactly what I have done:

(a) Download Python 2.7 and install it in a newly installed Windows 7 computer.

(b) Download py2exe and install it in the sample computer.

(c) Download ChartDirector for Python and unzip it in c:\\ChartDirector

(d) Copy all files from "c:\\ChartDirector\\lib" to "c:\\ChartDirect\\pythondemo"

(e) Open a command shell, "cd \\ChartDirector\\pythondemo". You should be able to run
the command "python simplebar.py" normally.

(f) Create the setup.py as mentioned in my last message and put it in
"c:\\ChartDirect\\pythondemo".

(g) Run "python setup.py py2exe"


In your case, please try to use my setup.py first (which uses "simplebar.py", not
"ChartTest.py"). This is just to test if it works with ChartDirector. The "ImportError: No
module named pychartdir27" you see is because py2exe cannot find the "pychartdir27".
To find this file, the file needs to be in a place that py2exe will search for. I am not sure
which place py2exe will search for. In my testing, I found that putting all the files in the
same directory as the script and also running the py2exe using a command shell in that
directory works.

I noted that in the error message, it mentions about "pychartdir.pyo". I am not sure what
is "pychartdir.pyo" as ChartDirector does not have this file. Is this file created by you or
is it automatically inferred to by py2exe? The standard method to import ChartDirector is
"from pychartdir import *" or "import pychartdir"

The error about "_sysconfigdata" should be unrelated to ChartDirector. From my
understanding, it is a standard Python module, and is possibly used by "distutils.core",
which is also a standard Python module. According to the official py2exe web site, the
first line of setup.py should be "from distutils.core import setup". Is it possible you have
more than one Python version in your computer? Sometimes mixing Python versions may
cause similar issues.


Regards
Peter Kwan

  Re: Problems with py2exe
Posted by Peter Kwan on Feb-11-2014 04:17
Hi taylor,

Have you also copied the pychartdir27.pyd to the same directory that you use to run the
setup script? For example, if your setup script is in the c:\\ChartDirector\\pythondemo
subdirectory, have you also copied "pychartdir27.pyd" to that directory?

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by Taylor on Feb-13-2014 11:33
Hi Peter,
  Yes, I also copied the pychartdir27.pyd,but not work. Now i gived up py2exe, and try to test cx_Freeze. By using the following setup.py script,it work.But need to copy 'chartdir.dll' file  together with the executable file ,then it work well.I don't know how to include the 'chartdir.dll'
file in the following script, and every thing need to test from the begining by use cx_Freeze. Because i want to compile to one exe file ,and in my big main program with many sub-programs and icons .I got headache now.

#!/usr/bin/evn python'
# -*- coding: utf-8 -*-
import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"build_exe":"exefile"
                    ,"packages": ["os"]
                    ,"excludes": ["tkinter"]
                    ,"includes":["pychartdir27"]
                    }

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "ChartTest",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("ChartTest.py", base=base)])



Peter Kwan wrote:

Hi taylor,

Have you also copied the pychartdir27.pyd to the same directory that you use to run the
setup script? For example, if your setup script is in the c:\\ChartDirector\\pythondemo
subdirectory, have you also copied "pychartdir27.pyd" to that directory?

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by Peter Kwan on Feb-14-2014 01:22
Hi Taylor,

I have never used cx_Freeze before, and I had never used py2exe before I saw this post.
Anyway, I suppose there must be some method for cx_Freeze to include a file. I browse the
cx_Freeze web site and find that its FAQ suggests using include-files:

http://cx-freeze.readthedocs.org/en/latest/faq.html#problems-with-running-frozen-
programs

Hope this can help.

Regards
Peter Kwan

  Re: Problems with py2exe
Posted by taylor on Feb-16-2014 01:50
Hi Peter,
Many Many thanks for your help, Now i can use cx_Freeze to overcome the problem. And start to enjoy in chartdirector.

Peter Kwan wrote:

Hi Taylor,

I have never used cx_Freeze before, and I had never used py2exe before I saw this post.
Anyway, I suppose there must be some method for cx_Freeze to include a file. I browse the
cx_Freeze web site and find that its FAQ suggests using include-files:

http://cx-freeze.readthedocs.org/en/latest/faq.html#problems-with-running-frozen-
programs

Hope this can help.

Regards
Peter Kwan