13

I'm unable to import entry point console scripts in my python package. Looking for help debugging my current issue, as I have read every relevant post on the issue.

Here is what my directory structure looks like:

├── ContentAnalysis
│   ├── __init__.py
│   ├── command_line.py
│   ├── document.py
│   ├── entities.py
│   ├── sentiment.py
│   ├── summary.py
│   ├── text_tokenize.py
│   ├── tokens.py
├── local-requirements.txt
├── requirements.txt
├── server-requirements.txt
├── setup.py
└── tests
    ├── tests.py
    └── tests.pyc

Here is what my setup.py looks like

from setuptools import setup

config = {
    'description': 'Tools to extract information from web links',
    'author': 'sample',
    'version': '0.1',
    'install_requires': ['nose'],
    'packages': ['ContentAnalysis'],
    'entry_points': {
        'console_scripts': ['content_analysis=ContentAnalysis.command_line:main'],
    },
    'name':'ContentAnalysis',
    'include_package_data':True
}

setup(**config)

I've installed the package and verified that content_analysis is reachable from the command line. I've also verified that my ContentAnalysis package is importable from the python interpreter from any cd in the computer. Yet I still get an "Entry point not found error on execution"

grant@DevBox2:/opt/content-analysis$ content_analysis -l 'http://101beauty.org/how-to-use-baking-soda-to-reduce-dark-circles-and-bags-under-the-eyes/'
Traceback (most recent call last):
  File "/opt/anaconda2/bin/content_analysis", line 11, in <module>
    load_entry_point('ContentAnalysis==0.1', 'console_scripts', 'content_analysis')()
  File "/opt/anaconda2/lib/python2.7/site-packages/setuptools-26.1.1-py2.7.egg/pkg_resources/__init__.py", line 565, in load_entry_point
  File "/opt/anaconda2/lib/python2.7/site-packages/setuptools-26.1.1-py2.7.egg/pkg_resources/__init__.py", line 2588, in load_entry_point
ImportError: Entry point ('console_scripts', 'content_analysis') not found

Any help or tips towards debugging this is appreciated

Edit #1:

Attempting to debug the issue, I noticed the command_line is not reachable as a submodule within ContentAnalysis

>>> import ContentAnalysis
>>> ContentAnalysis.tokens
<module 'ContentAnalysis.tokens' from '/opt/anaconda2/lib/python2.7/site-packages/ContentAnalysis/tokens.pyc'>
>>> ContentAnalysis.command_line
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'command_line'
>>> 

It appears that command_line is not being added to the relevant site_packages folder.

grant@DevBox2:/opt/anaconda2/lib/python2.7/site-packages/ContentAnalysis$ ls
data          entities.py   __init__.pyc   summary.py        text_tokenize.pyc
document.py   entities.pyc  sentiment.py   summary.pyc       tokens.py
document.pyc  __init__.py   sentiment.pyc  text_tokenize.py  tokens.pyc

I wonder why?

GrantD71
  • 1,787
  • 3
  • 19
  • 27

5 Answers5

5

Investigation of the relevant site-packages folder clued me that my python setup.py install command was not putting all the relevant files where they needed to be.

I'm still not 100% of the underlying cause of the issue, but I was only able to get my site-packages folder to truly update by passing setup.py the --force argument as in

python setup.py install --force

Now my site-packages folder contains the relevant command_line.py, and the console entry point works as expected.

GrantD71
  • 1,787
  • 3
  • 19
  • 27
  • 1
    I'm having the exact same problem (command_line.py is not being copied), but `python setup.py install --force` doesn't fix it. Have you learned anything more about this issue? – Codie CodeMonkey Jan 10 '18 at 08:55
  • One additional potential problem is if a user is running `python setup.py install --force` as compared to `sudo python setup.py install --force`. It's possible that different users will have different path variables, and you might lose the path variable you need to find the script. https://stackoverflow.com/questions/39255544/conda-setuptools-install-changes-shebangs-to-default-python-install – GrantD71 Jan 10 '18 at 17:50
  • 1
    Thanks. I ended up getting around this by using wheels: `python setup.py bdist_wheel` followed by `pip install .`. – Codie CodeMonkey Jan 10 '18 at 23:11
1

Hmm, this is all a bit opaque to debug -- I think the implementation of entry points might suffer from too much indirection. So entry points work as follows:

  • When installing a script with an entry point a placeholder script is placed on your path
  • This script contains the name of your package, and the name of the entry point
  • This is used to look up an entry in a metadata file called entry_points.txt which lives in egg-info directories or dist-info directories

I suspect this level of indirection allows you to change what entry points point at without reinstalling the binary entry points, which may be deemed as advantageous.

This means that if there are stale or shadowing dist-info or egg-info files can lead to the wrong entry points being loaded.

A quick

strace 2> >(grep --line-buffered entry_points.txt) -e open package

will tell you which entry point is being used. You can then verify if this is stale / incorrect.

Att Righ
  • 1,439
  • 1
  • 16
  • 29
1

Using --force did not solve the problem for me. Instead, I completely uninstalled the package and then installed it again normally.

stefanbschneider
  • 5,460
  • 8
  • 50
  • 88
1

I did have a similar issue that occurred after renaming my entry_point, in your case that would be changing "content_analysis=" in the list of the console_scripts key. With python3.6, pip19.3.1, the entry_point script was correctly installed in the install_dir/bin/ directory but I was unable to run it, it raised below error.

ImportError: Entry point ('console_scripts', 'dldemos_server') not found

I tried to pip uninstall, but the problem was still there;

What solved the issue in my case was:

  1. Remove manually every file that have been installed. The entry points in install_dir/bin/.., and the module and egg files in install_dir/lib/python3.6/site-packages/...;

  2. Install the module (I did python3 -m pip install -e . --user since I wanted a develop install)

Then I was able to run my entry point.

shuberman
  • 1,416
  • 6
  • 21
  • 38
Jeremy
  • 21
  • 4
0

in your config try changing:'name':'content_analysis'

'console_scripts': ['content_analysis=ContentAnalysis.command_line:main'] and 'name':'content_analysis' should be same