question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Entry points on Windows do not set __package__ correctly

See original GitHub issue

Werkzeug provides a reloader for WSGI applications like Flask. Because Python behaves slightly differently when run as python file vs python -m module, the reloader needs to figure out how Python was invoked in order to invoke it the same way on reload. To determine if -m module was used, it looks at __main__.__package__. If it’s set to None, it was run as a file, otherwise it was run as a package. See explanation here and in PEP 366:

When the main module is specified by its filename, then the __package__ attribute will be set to None.

However, entry points on Windows are not behaving this way. Instead, __package__ is the empty string when running an entry point. This caused an issue with the Werkzeug 0.15.5 release, see pallets/werkzeug#1614.

Additionally, entry points on Windows are behaving correctly when the package is installed in editable mode (pip install -e .), and they behave consistently and correctly on other platforms. So there seems to be an inconsistency in how setuptools creates entry points on Windows.

The following two files reproduce this. Use pip install -e . then run ep-example, observe the output. Then use pip install . and ex-example, and observe that the output is different. You can confirm that the output is consistent by doing the same on Linux.

ep_example.py:

import sys

def main():
    __main__ = sys.modules["__main__"]
    print("__main__.__package__:", repr(__main__.__package__))

setup.py:

from setuptools import setup

setup(
    name="ep-example",
    version="0.1.0",
    py_modules=["ep_example"],
    entry_points={"console_scripts": ["ep-example=ep_example:main"]},
)

Correct behavior for editable install on Windows, and editable and dist installs on Linux or Mac:

> pip install -e .
> ep-example
__main__.__package__: None

Incorrect behavior for dist install on Windows:

> pip install .
> ep-example
__main__.__package__: ''

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
davidismcommented, Sep 4, 2019

I’m not clear that it’s the script, since the pip and distlib scripts behave correctly on Linux. Maybe it’s some quirk of the exe.

1reaction
chrahuntcommented, Aug 31, 2019

The actual change may end up being in pypa/distlib, which pip vendors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setuptools console_script entry point not found with install but ...
The problem is in your packages argument. You only specify: packages=['fbuildbot', ],. not packages=['fbuildbot', 'fbuildbot.create'],.
Read more >
Fixed: "Procedure Entry Point Could Not Be Located" Error
This article will provide some solutions to the Windows 10 error “The procedure entry point could not be located in the dynamic link...
Read more >
Python Apps the Right Way: entry points and scripts
The best way to handle this is the Entry Points mechanism of Setuptools, and a __main__.py file. It's quite easy to implement.
Read more >
Troubleshooting packaging, deployment, and query of ...
Error code Value Description and possible causes E_INVALIDARG 0x80070057 ERROR_INSTALL_INVALID_ PACKAGE 0x80073CF2 The package data isn't valid. ERROR_INSTALL_NETWORK_ FAILURE 0x80073CF5 The package can't be downloaded.
Read more >
KB5005652—Manage new Point and Print default driver ...
Default behavior: Setting this value to 1 or if the key is not defined or not present, will require administrator privilege to install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found