1

I have written the beginnings of a package that I would like to distribute, but I am having issues. When I place the sample_test.py in the primary directory, the script runs just fine. When I attempt to create a distribution and run it sample_test.py from anywhere, it doesn't work: ImportError: No module named 'script_functions'.

To install, I am running python setup.py sdist then python setup.py install. Both of these execute without error. Also, to keep from 'polluting' my core python environment, I am creating a new virtual environment and installing to that.

The moog_visa.py and moog_daqmx.py files contain classes that are used by script_functions.py. The hw_test_runner.py and script_functions.py contain simple functions that I wish to make available in my python environment. I'm not sure if this is relevant...

Directory structure:

\hw_test_runner
    \examples
        \sample_test.py
    \hw_test_runner
        \__init__.py
        \hw_test_runner.py
        \moog_daqmx.py
        \moog_visa.py
        \script_functions.py
    \setup.py

My setup script contains:

from setuptools import setup

setup(name='hw_test_runner',
      version='0.12',
      description='Scriptable hardware test suite',
      author='me',
      author_email='xxx@XXX',
      url='https://my_url.com',
      packages=['hw_test_runner'],
      install_requires=['numpy', 'pyvisa', 'PyDAQmx']
      )

And init.py:

from hw_test_runner.script_functions import *
from hw_test_runner.hw_test_runner import *

In hw_test_runner.py:

from hw_test_runner.script_functions import *

<... more code below ... >

In `script_functions.py:

from hw_test_runner import moog_visa
from hw_test_runner import moog_daqmx

<... more code below ... >

I have tried various incarnations of the import statement within the __init__.py file, but haven't gotten anything working. I suspect that there is one line off somewhere that I just don't have the experience to easily spot.

Edit - More Information

After playing around a bit on the command line, I haven't found the problem, but I believe that the issue may lay with PyCharm. I can execute sample_test.py on the command line but not within PyCharm. PyCharm is set up to use the appropriate virtual environment, but there is apparently still something else missing.

slightlynybbled
  • 2,408
  • 2
  • 20
  • 38
  • Oh, heh, PyCharm. Please take a look at [this answer](http://stackoverflow.com/a/22861755/2904896), or the rest of the thread may help you. – metatoaster Sep 13 '16 at 12:20
  • 1
    @metatoaster Thank you for the advice. I have found that things are working correctly on the command line and have updated the question. I believe that the problem has something to do with PyCharm. Your comment surprises me, though, I thought that I *had* to have an `__init__.py` file... you are saying that I don't? – slightlynybbled Sep 13 '16 at 12:21
  • If you are not targeting anything less than Python 3.3, you can omit that. Unless of course what you seem to be doing is providing alias import locations, but that can make things complicated for your package structure. – metatoaster Sep 13 '16 at 12:22

0 Answers0