C/C++ Import

7

7H3LaughingMan

To make the background information short, I am trying to take a
program that uses Python for scripting and recompile it for Linux
since it originally was built to run on Win32. The program itself was
designed to be able to be compiled on Linux and someone made there on
release with source that added python scripting. After some issues I
got it to compile but now it is unable to import the files that it
needs.

The program is running the following code...
PyImport_Import( PyString_FromString("python.PlayerManager") );

This is meant to import the file PlayerManager.py inside of the python
folder. However it throws the following Python Error (Gotten through
PyErr_Print())
ImportError: No module named python.PlayerManager

I am using 2.6.4 so I can't call it by the filename, does anyone know
how to do a proper import?
 
7

7H3LaughingMan

The folder does contain a file named '__init__.py'. However it
contains nothing inside of the file.
 
T

Terry Reedy

To make the background information short, I am trying to take a
program that uses Python for scripting and recompile it for Linux
since it originally was built to run on Win32. The program itself was
designed to be able to be compiled on Linux and someone made there on
release with source that added python scripting. After some issues I
got it to compile but now it is unable to import the files that it
needs.

The program is running the following code...
PyImport_Import( PyString_FromString("python.PlayerManager") );

This is meant to import the file PlayerManager.py inside of the python
folder. However it throws the following Python Error (Gotten through
PyErr_Print())
ImportError: No module named python.PlayerManager

I am using 2.6.4 so I can't call it by the filename, does anyone know
how to do a proper import?

Your 'python' package directory must be in a directory listed in
sys.path. I would print that check.
 
A

Austin Bingham

Just to elaborate on Terry's point a bit, sys.path is influenced (in
part) by the PYTHONPATH environment variable. If you find that the
directory containing 'python' is not in sys.path (which you can check
with 'import sys; print sys.path'), add that directory to PYTHONPATH
and try again. This may not be the solution you ultimately end up
using, but it'll get you pointed in the right direction.

Austin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top