2
  • Windows 7 Professional (64 bit)
  • Python 2.7.14 (2.7.14150 64 bit)
  • mock 2.0.0

When I just run python -c "import mock" from command prompt (as an administrator) it yields Exception:

Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "C:\Python27\lib\site-packages\mock\__init__.py", line 2, in <module>
 import mock.mock as _mock
 File "C:\Python27\lib\site-packages\mock\mock.py", line 71, in <module>
 _v = VersionInfo('mock').semantic_version()
 File "C:\Python27\lib\site-packages\pbr\version.py", line 461, in semantic_version
 self._semantic = self._get_version_from_pkg_resources()
 File "C:\Python27\lib\site-packages\pbr\version.py", line 448, in _get_version_from_pkg_resources
 result_string = packaging.get_version(self.package)
 File "C:\Python27\lib\site-packages\pbr\packaging.py", line 755, in get_version
 name=package_name))
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given t
o pbr.version.VersionInfo. Project name mock was given, but was not able to be found.
asked Feb 1, 2018 at 8:06

2 Answers 2

1

The answer is in the exception message at the end: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name mock was given, but was not able to be found.

This seems to be an issue with pbr package. Have you tried to reinstall it or remove it to test if this fixes the issue (which would indicate you need to concetrate on pbr)?

answered Feb 1, 2018 at 8:13
Sign up to request clarification or add additional context in comments.

4 Comments

@sophoros I uninstalled pbr and run python -c "import mock" again. It complained on missing pbr. It seems that this pbr library is a must for mock. Also, after installing pbr back. The same exception popped out! Any new ideas?
Then I suggest that you check setup.cfg (maybe in the %PATH%) as pointed out in the message above. Maybe there indeed is a mismatch in versions for some reasons.
@sophoros I went that way, and check the setup.cfg only to understand that is the same as the guy next to me had(and he does not have my problems). Then I dive into the pbr scripts, and found the source of the exception in function get_version, in module packaging.py. When I reviewed this function I noticed that I can enforce this version by setting the environment variable PBR_VERSION to '0.1' (this is the version I had found in setup.cfg before). After this, there were no Exceptions, and unit testing (which I used mock for) WORKS!
That's reassuring! Good that you were able to fix it!
0

I had the same issue and in my case updating setuptools was the fix. I've found the suggestion here: https://github.com/testing-cabal/mock/issues/314

Before update I had setuptools 0.6c11 and I've updated to latest 39.2.0.

pip install --upgrade setuptools

or actually in my case I had to download and install locally since production server has no connection to internet:

pip download setuptools
pip install setuptools-39.2.0-py2.py3-none-any.whl
answered Jun 4, 2018 at 12:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.