Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PIP convert underscores to dashes

I am trying to install a Pyramid app -- let's say test_app. inside a virtual environment and it is getting installed as test-app (pip freeze output shows it test-app==0.0).

Because of this, I can not import the package.

How should I fix this problem?

More info: http://mail.python.org/pipermail/distutils-sig/2011-August/017935.html

I am using pip version 1.3.1

setup.py:

import os

from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.txt')).read()
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()

requires = [
    'pyramid',
    'pyramid_debugtoolbar',
    'waitress',
    ]

setup(name='test_app',
      version='0.0',
      description='test_app',
      long_description=README + '\n\n' + CHANGES,
      classifiers=[
        "Programming Language :: Python",
        "Framework :: Pyramid",
        "Topic :: Internet :: WWW/HTTP",
        "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
        ],
      author='',
      author_email='',
      url='',
      keywords='web pyramid pylons',
      packages=find_packages(),
      include_package_data=True,
      zip_safe=False,
      install_requires=requires,
      tests_require=requires,
      test_suite="test_app",
      entry_points="""\
      [paste.app_factory]
      main = test_app:main
      """,
      )

UPDATE:

to summarize the findings so far:

  • It is normal that pip reports the package name as test-app.
  • It is not normal that the egg link is pointing to your virtual env root.
  • But the fact that the .egg-info file is created inside your virtual env root as well points to develop using that directory as the egg root.

Update 2021

I have now started using Poetry instead of pip for all my new Python projects. It works well for both normal projects and Jupyter notebooks. With its better developer experience for package management all I'd have to do for the above example would be

poetry run xyz

where xyz is a script that I define within the spec file (akin to package.json for npm). I would be able to import my own package as all other packages.

like image 886
treecoder Avatar asked May 05 '13 13:05

treecoder


1 Answers

Update 2021

Use Poetry instead of pip.


Original answer:

So, finally after a lot of fiddling around, I've found the solution -- which is annoyingly simple.

I am using virtualenv and am installing the package in the development mode.

I was installing the package from the wrong location. Turns out that the location (directory) from which you run python setup.py develop is indeed the one that goes into the .egg-link file.

You should install the package into the virtual environment FROM the location where your code is.

So, for example, let's say your code resides in '/a/b' and your virtualenv env is in '/x/y/env', then you should install the package like this:

$ cd /a/b
$ /x/y/env/bin/python setup.py develop

This will install the package properly.

Hence, the '-' and '_' issue is not a problem and you should be careful about the location from where you are installing the package in the develop mode.

like image 172
treecoder Avatar answered Oct 15 '22 09:10

treecoder