Setuptools with entry_points

I would like to install a script with setuptools and do the following setup:

There are files in my development directory

  • setup.py and
  • z_script.py.

The z_script.py file is as follows:

 def main(): print "Running..." 

and my setup.py looks like this:

 from setuptools import setup setup( name = 'z_script', version = '0.2', entry_points = {"console_scripts": ["z_script = z_script:main"]}, ) 

When I run python setup.py install , the script successfully installs into the correct bin directory.

However, when I run the script with z_script , an error occurs:

 Traceback (most recent call last): File "./z_script", line 8, in <module> load_entry_point('z-script==0.2', 'console_scripts', 'z_script')() File "/home/woltan/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point File "/home/woltan/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2221, in load_entry_point File "/home/woltan/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1954, in load ImportError: No module named z_script 

The bin is accessible through the PATH environment variable from the idea that the system and the PYTHONPATH environment variable PYTHONPATH set when z_scirpt .

And now to my question:

What is wrong with my setup? Why could not the script find the correct module?

+4
source share
1 answer

You will not specify setuptools to install z_script . Use find_packages or list z_script in the py_modules key.

 ... packages = find_packages(), ... 

or

 ... py_modules = ['z_script'], ... 
+5
source

Source: https://habr.com/ru/post/1392018/


All Articles