There is a package in PyPI called neat-python (yes, with a hyphen). I can install it just fine but can't import it into Python. I've tried underscores, parentheses, and making the name a string but of course the import statement doesn't allow them. Does PyPI actually accept packages with illegal Python names or is there a solution I'm overlooking?
Python packages and modules can not use hyphens, only underscores. This section of PEP-8 gives us guidance: Package and Module Names: Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.
You can't have hyphens in variable names in python. That's the subtraction operator. Consider using an underscore instead: education_numType = ...
__import__() . This means all semantics of the function are derived from importlib. __import__() . The most important difference between these two functions is that import_module() returns the specified package or module (e.g. pkg. mod ), while __import__() returns the top-level package or module (e.g. pkg ).
So, yes, you can have a number in both a project name and a module name, and the project name can even begin with one!
hyphen is not allowed in import syntax. In the case of 'neat-python' the package is simply installed as 'neat':
import neat
you can check this yourself by looking in your site-packages directory (for me, that is /usr/local/lib/python3.7/site-packages
).
Edit: and yes, this is allowed for PyPI packages, and it can be annoying. Usually the actual package name will be some very similar variant of the name used to install from PyPI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With