Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import workalendar in ipython (DistributionNotFound) #74

Closed
flyte opened this issue May 1, 2014 · 22 comments
Closed

Cannot import workalendar in ipython (DistributionNotFound) #74

flyte opened this issue May 1, 2014 · 22 comments

Comments

@flyte
Copy link

flyte commented May 1, 2014

It works when I use the normal python console, but not with ipython. I've tried with and without ipython installed in the virtualenv (it's installed globally).

Steps to recreate:

> virtualenv ve
> . ve/bin/activate
> pip install workalendar
> ipython
In [1]: import workalendar
---------------------------------------------------------------------------
DistributionNotFound                      Traceback (most recent call last)
<ipython-input-1-375fa58b25cd> in <module>()
----> 1 import workalendar

/home/flyte/temp/workalendar/ve/lib/python2.7/site-packages/workalendar/__init__.py in <module>()
      4 
      5 #: Module version, as defined in PEP-0396.
----> 6 __version__ = pkg_resources.get_distribution(__package__).version

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in get_distribution(dist)
    328     """Return a current distribution object for a Requirement or string"""
    329     if isinstance(dist,basestring): dist = Requirement.parse(dist)
--> 330     if isinstance(dist,Requirement): dist = get_provider(dist)
    331     if not isinstance(dist,Distribution):
    332         raise TypeError("Expected string, Requirement, or Distribution", dist)

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in get_provider(moduleOrReq)
    207     """Return an IResourceProvider for the named module or requirement"""
    208     if isinstance(moduleOrReq,Requirement):
--> 209         return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    210     try:
    211         module = sys.modules[moduleOrReq]

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in require(self, *requirements)
    684         """
    685 
--> 686         needed = self.resolve(parse_requirements(requirements))
    687 
    688         for dist in needed:

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in resolve(self, requirements, env, installer, replacement)
    582                         # unfortunately, zc.buildout uses a str(err)
    583                         # to get the name of the distribution here..
--> 584                         raise DistributionNotFound(req)
    585                 to_activate.append(dist)
    586             if dist not in req:

DistributionNotFound: workalendar

My pip freeze:

argparse==1.2.1
ipython==2.0.0
lunardate==0.1.4
pyCalverter==1.6.1
pyephem==3.7.5.2
python-dateutil==2.2
pytz==2014.2
six==1.6.1
workalendar==0.1
wsgiref==0.1.2

pip version:

pip 1.5.4 from /home/flyte/temp/workalendar/ve/local/lib/python2.7/site-packages (python 2.7)

setuptools version:

setuptools 2.2
@brunobord
Copy link
Member

I'm not sure about this. Will investigate. but... later ;o)

@brunobord
Copy link
Member

I can't reproduce the bug, I'm afraid. Using my "OS" IPython (installed via apt-get), it works.
I've tried to install IPython 2.0.0 inside the virtualenv and it's still working fine.

I think that this DistributionNotFound issue could be related to your own setup (strange PYTHONPATH? weird ipython install and mangle in the paths?). The fact that it's working with the stock python binary is a clue, methinks.

I'm keeping this issue opened ; you may want to report your investigations here, in case it could be useful to somebody else.

@JanMalte
Copy link
Contributor

Can't reproduce either. I think this issue can be closed for now.

@flyte
Copy link
Author

flyte commented Jan 18, 2016

To be honest, I don't remember making this issue, but I've just tried again on a new laptop and I can still reproduce the issue. It seems a bit more nuanced than I originally made out.

# WORKS (venv pip-installed ipython v4.0.2)
virtualenv ve
. ve/bin/activate
pip install workalendar
pip install ipython
ipython -c "import workalendar"

# DOESN'T WORK (globally pip-installed ipython v4.0.2)
virtualenv ve
. ve/bin/activate
pip install workalendar
ipython -c "import workalendar"

# DOESN'T WORK (the weirdest)
virtualenv ve
. ve/bin/activate
pip install workalendar
ipython -c "import workalendar"  # Nope
pip install ipython
ipython -c "import workalendar"  # Nope

@JanMalte
Copy link
Contributor

Could you just make sure, the local ipython is used in the last example by running
which ipython just after installing ipython using pip and after trying to import workalendar?

virtualenv ve
. ve/bin/activate
pip install workalendar
ipython -c "import workalendar"
which ipython
pip install ipython
which ipython
ipython -c "import workalendar"
which ipython

@flyte
Copy link
Author

flyte commented Jan 18, 2016

DistributionNotFound: The 'workalendar' distribution was not found and is required by the application
(ve)flyte@demosthenes ~ $ which ipython
/home/flyte/ve/bin/ipython

@JanMalte
Copy link
Contributor

Running ipython itself in the venv is working?

@flyte
Copy link
Author

flyte commented Jan 18, 2016

(ve)flyte@demosthenes ~ $ ipython
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 

Yep

@flyte
Copy link
Author

flyte commented Jan 18, 2016

Although that's strange - it still has that warning about "attempting to work in a virtualenv".

@JanMalte
Copy link
Contributor

I tried all your examples and they all worked well. Is it possible four you to uninstall the global ipython package? Maybe only this is broken and not workalendar itself, as a complete local venv setup worked for you.

@flyte
Copy link
Author

flyte commented Jan 18, 2016

It looks like when you run global IPython inside a virtualenv, then install IPython within that same virtualenv, it still somehow uses the global version, even though 'which' reports otherwise.

That would mean that the problem relating to workalendar is that it doesn't work in a globally pip-installed version of IPython when it's installed in a virtualenv.

@JanMalte
Copy link
Contributor

Well, I'm not sure if it is only a workalendar related issue.

@flyte
Copy link
Author

flyte commented Jan 18, 2016

Indeed, it seems that the issue is really an IPython one.

@JanMalte
Copy link
Contributor

So this issue can be closed here?

@flyte
Copy link
Author

flyte commented Jan 18, 2016

It is, of course, up to you whether you want to investigate how this can be mitigated, but if it were up to me I'd probably close it and get on with more important things :)

@brunobord
Copy link
Member

sorry it took so long. did you manage to solve it?

@ghost
Copy link

ghost commented Jun 7, 2017

Hi, I also have problem with "DistributionNotFound"

(venv)user@stage1:~$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import workalendar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/venv/local/lib/python2.7/site-packages/workalendar/__init__.py", line 6, in <module>
    __version__ = pkg_resources.get_distribution(__package__).version
  File "/home/user/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 311, in get_distribution
  File "/home/user/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 197, in get_provider
  File "/home/user/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
  File "/home/user/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: workalendar

I fix it by update setuptools to newest version.
pip install -U setuptools

@brunobord
Copy link
Member

could you please give me the result of the command pip freeze -l?

@ghost
Copy link

ghost commented Jun 7, 2017

@brunobord

(venv)user@stage1:~$ pip freeze -l
arrow==0.5.4
astroid==1.4.8
backports.functools-lru-cache==1.3
beautifulsoup4==4.5.1
blessings==1.6
boto==2.38.0
bpython==0.16
cffi==1.9.1
click==6.6
configparser==3.5.0
contextlib2==0.5.4
coverage==4.2
cryptography==1.6
cssmin==0.2.0
curtsies==0.2.11
decorator==4.0.10
diff-match-patch==20121119
Django==1.10.4
django-cors-headers==1.1.0
django-crispy-forms==1.6.1
django-dajax==0.9.2
django-dajaxice==0.7
django-datetime-widget==0.9.3
django-dbbackup==3.1.3
django-debug-toolbar==1.6
django-discover-runner==1.0
django-extensions==1.7.5
django-filter==1.0.1
django-generix==1.3.1
django-jenkins==0.110.0
django-pipeline==1.6.9
django-reversion==2.0.8
django-reversion-proxymodel==1.8.0
django-rq==0.9.4
django-storages==1.5.1
django-test-pep8==0.1
django-webtest==1.8.0
django-wkhtmltopdf==3.1.0
djangorestframework==3.5.3
dropbox==2.2.0
ecdsa==0.13
enum34==1.1.6
Fabric==1.12.0
factory-boy==2.8.1
fake-factory==0.7.2
Faker==0.7.7
freezegun==0.3.8
funcsigs==1.0.2
futures==3.0.5
google-api-python-client==1.6.2
greenlet==0.4.11
gunicorn==19.6.0
httplib2==0.10.3
idna==2.1
ipaddress==1.0.17
isort==4.2.5
isoweek==1.3.1
junit-xml==1.7
lazy-object-proxy==1.2.2
linecache2==1.0.0
logilab-common==1.3.0
lunardate==0.1.5
Markdown==2.6.7
mccabe==0.5.2
mock==2.0.0
oauth2client==4.1.1
paramiko==2.0.2
pbr==1.10.0
pep8==1.7.0
Pillow==3.4.2
ply==3.4
psycopg2==2.6.2
pyasn1==0.1.9
pyasn1-modules==0.0.9
pyCalverter==1.6.1
pycparser==2.17
pycrypto==2.6.1
pyephem==3.7.6.0
pyflakes==1.3.0
Pygments==2.1.3
pylint==1.6.4
python-dateutil==2.6.0
pytz==2016.7
PyYAML==3.12
raven==5.32.0
redis==2.10.3
requests==2.12.3
rq==0.7.0
rsa==3.4.2
six==1.10.0
slimit==0.8.1
sqlparse==0.2.2
times==0.7
traceback2==1.4.0
Unidecode==0.4.19
Unipath==1.1
unittest2==1.1.0
uritemplate==3.0.0
urllib3==1.19.1
vobject==0.9.3
waitress==1.0.1
wcwidth==0.1.7
WebOb==1.6.3
WebTest==2.0.23
workalendar==1.2.0
wrapt==1.10.8

@brunobord
Copy link
Member

maybe we could get rid of this issue by forcing a certain version of setuptools, or define a minimum version. On my (old) 14.04 Ubuntu LTS, the stock setuptools version is 3.3 ; the current latest I could install is 36.0.1.

With 3.3 it works like a charm. Maybe we could just add this line in the requirements:

setuptools>=3.3

(sidenote: is it me or is the versionning of setuptools became insane?)

@Natim
Copy link
Contributor

Natim commented Jun 7, 2017

Yes setuptools is now released automatically each time a commit is merge to master with a version bump.

brunobord added a commit that referenced this issue Jun 7, 2017
this version is known to be buggy and causes ``DistributionNotFound`` exceptions.
@brunobord brunobord self-assigned this Jun 7, 2017
@brunobord
Copy link
Member

working on it, incoming micro-PR.

brunobord added a commit that referenced this issue Jun 7, 2017
… ``DistributionNotFound`` exceptions with obsolete versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants