Exception using mock library, python unit testing issue - python

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.

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)?

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

Related

About the error in the installation steps of readthedocs local server

I'm trying to install readthedocs on my local gitlab server and I'm following the guide in the link.
ReadThedocs Guide
Here's the python version and pip version I'm using;
Python3.9
Pip3.9
To run the virtual pip environment, I use the following command.
python3.9 -m venv tutorial-env # I completed the install process with this command.
source tutorial-env/bin/activate # with this command I access the virtual pip environment
my steps in the virtual pip environment;
I run this from the readthedocs installation steps.
(tutorial-env) [redhat#gitlab tutorial-env]$ pip install -r requirements.txt
And no error occurred.
(tutorial-env) [redhat#gitlab tutorial-env]$ python3.9 /home/redhat/readthedocs.org/manage.py migrate
Gave the following error message
[debug ] Using slumber v2. [readthedocs.api.v2.client] api_host=http://127.0.0.1:8000 username=test
Traceback (most recent call last):
File "/home/redhat/readthedocs.org/manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/home/redhat/readthedocs.org/readthedocs/core/apps.py", line 15, in ready
import readthedocs.core.signals # noqa
File "/home/redhat/readthedocs.org/readthedocs/core/signals.py", line 17, in <module>
from readthedocs.core.unresolver import unresolve
File "/home/redhat/readthedocs.org/readthedocs/core/unresolver.py", line 16, in <module>
#dataclass(slots=True)
TypeError: dataclass() got an unexpected keyword argument 'slots'
However, when I run the python manage.py migrate command in the pip virtual environment, I get the following error message and I can't complete the installation process. What exactly this problem points to?
Thank you for support.
I haven't tried any solutions because I don't understand what is causing the problem.
You are following an outdated and unofficial documentation of Read the Docs (https://read-the-docs.readthedocs.io/en/latest/install.html). The official guide is a lot more updated and uses Docker now, which is easier to setup. Please, read the official guide at https://docs.readthedocs.io/en/latest/development/install.html

Error when trying to upgrade a python package

I have git pulled a python package (I think that is the correct terminology) that I already had installed and working.
So now it is up to date, apparently I needed to update it using pip. I did the following:
pip install the_package --upgrade
But I got the following error message:
Exception:
Traceback (most recent call last):
File "/opt/work/python/2.7.13/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/opt/work/python/2.7.13/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
wb.build(autobuilding=True)
File "/opt/work/python/2.7.13/lib/python2.7/site-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/opt/work/python/2.7.13/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/opt/work/python/2.7.13/lib/python2.7/site-packages/pip/req/req_set.py", line 666, in _prepare_file
check_dist_requires_python(dist)
File "/opt/work/python/2.7.13/lib/python2.7/site-packages/pip/utils/packaging.py", line 48, in check_dist_requires_python
feed_parser.feed(metadata)
File "/opt/work/python/2.7.13/lib/python2.7/email/feedparser.py", line 177, in feed
self._input.push(data)
File "/opt/work/python/2.7.13/lib/python2.7/email/feedparser.py", line 99, in push
parts = data.splitlines(True)
AttributeError: 'NoneType' object has no attribute 'splitlines'
I'm not sure what the problem is. Could someone please point me in the right direction?
I can't say much about the error you're seeing, but my best guess is that the version of the package from git is interfering with the pip installed one. Perhaps something went wrong when trying to upgrade starting with the gitHub version (or wherever it came from) and not with an officially published one.
If a package is available through PyPI you shouldn't need to do anything besides pip install <somepackage>. I would recommend removing all files downloaded via git and those modules in your python lib so you can start over completely. From there just use pip install <packagename>.
If you're not already in a python virtual environment I would recommend creating one too, so that these things are easier to fix.
Edit: I just found elsewhere on this site that you can use pip show <packagename> to show the install location of the package if you're not in a venv (or if you are).

pip error calling lsb_release when installing new package

I'm trying to configure 2 Ubuntu servers to use Python and Tensorflow for my project. I finished the 1st server, however, there are some very unusual and annoying errors with the 2nd one. This is the log when I run pip check on the 1st server:
~$: pip check
No broken requirements found.
And the error log on the 2nd one:
~$: pip check
No broken requirements found.
Traceback (most recent call last):
File "/home/mju-hpc-02/.local/bin/pip", line 11, in <module>
sys.exit(main())
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/__init__.py", line 233, in main
return command.main(cmd_args)
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/basecommand.py", line 251, in main
timeout=min(5, options.timeout)) as session:
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/basecommand.py", line 72, in _build_session
insecure_hosts=options.trusted_hosts,
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/download.py", line 329, in __init__
self.headers["User-Agent"] = user_agent()
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/download.py", line 93, in user_agent
from pip._vendor import distro
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/_vendor/distro.py", line 1050, in <module>
_distro = LinuxDistribution()
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/_vendor/distro.py", line 594, in __init__
if include_lsb else {}
File "/home/mju-hpc-02/.local/lib/python3.5/site-
packages/pip/_vendor/distro.py", line 931, in _get_lsb_release_info
raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero
exit status 1
This error also shows everytime I'm trying to install a new package with pip. Anyone faced similar problems with pip or having a way to diagnose the error?
EDIT 1:
As languitar suggestion, I ran lsb_release -a on both machines and this is the log on the 1st one:
~$: lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
2nd one:
~$: lsb_release -a
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 25, in <module>
import lsb_release
ImportError: No module named 'lsb_release'
You did not mention your Python version(s) available on your system.
Not sure how this happen, but often 'lsb_version' is available to run on python v2 and others on v3.
Most likely you have a multiple python version on your host.
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero
exit status 1
Is, indeed, failing because the 'lsb_release' library called by '/usr/bin/lsb_release' is not available for your particular Python version.
Your first attempt to fix this is simple:
sudo apt install lsb-release
Note is '-' and not '_'
Try again, if keep failing try the following: Look for your Python version library on /usr/lib, and confirm that 'lsb_release.py' is not there. Then, link the shared version to your library:
ln -sfv /usr/share/pyshared/lsb_release.py /usr/lib/python3.7/site-packages/lsb_release.py
Last resource, search /usr for any lsb_release.py and link it to your Python library.
find /usr -name lsb_release.py
You can just use default lsb_release or perhaps a bit modified version:
1 #!/bin/bash
171 [ -z "$LSB_VERSION" ] && LSB_VERSION="1.4"
172 #$MSG_NA
It seems your lsb_release binary is broken. Try to reinstall lsb-release (ubuntu or debian package).

SyntaxError: invalid syntax wheninstalling pip on OSX

I have installed pip according to instructions on pip website. Downloaded get-pip.py and insatlled it with python get-pip.py. Got a confirmation saying installation is successful. Apparently the moment i type pip i get following error:
[fh-mi-sdb99-ma:~/Downloads] sdb99% pip
/Library/Python/2.5/site-packages/pip-6.1.1-py2.5.egg/pip/__init__.py:211: Warning: 'as' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "/usr/local/bin/pip", line 8, in <module>
load_entry_point('pip==6.1.1', 'console_scripts', 'pip')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 271, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 2174, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 1907, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.5/site-packages/pip-6.1.1-py2.5.egg/pip/__init__.py", line 211
except PipError as exc:
^
SyntaxError: invalid syntax
i am not sure why is this happening..
Any suggestion that would help me to get pip installed correctly on my mac?
Thanks!
EDIT:
[fh-mi-sdb99-ma:~/Downloads] sdb99% python --version
Python 2.7.9
[fh-mi-sdb99-ma:~/Downloads] sdb99% pip --version
/Library/Python/2.5/site-packages/pip-6.1.1-py2.5.egg/pip/__init__.py:211: Warning: 'as' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "/usr/local/bin/pip", line 8, in <module>
load_entry_point('pip==6.1.1', 'console_scripts', 'pip')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 271, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 2174, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 1907, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.5/site-packages/pip-6.1.1-py2.5.egg/pip/__init__.py", line 211
except PipError as exc:
^
SyntaxError: invalid syntax
Second EDIT:
I have installed python 3.5 pkg but still when i type python on terminal, python 2.7 is initiated..
Your stack trace indicates that you are actually running python2.5
Verification
To verify your python version run python --version.
I would also verify your pip version by running pip --version.
Using the correct python
If you already installed python2.7, you can often specify it specifically, for example: python2.7 my_module.py. Try typing python in your terminal and tap TAB twice. This will list all the python* programs you have in your path. If python2.7 is not listed, you will need to install it.
Using the correct pip
Similar to the above about using the correct python, you should ensure you are using the correct pip.
Try typing pip into your terminal and tap TAB twice. This will list any extra pip versions you have. It is often easier to specify pip2.7.
Download and install Python3.4
If you haven't made a firm decision between python2 and python3, a nice feature of python3 is that python3.4 is bundled with pip, so you don't have to do anything to use it.
Update
Python 2 is end-of-life. Python 3.4+ comes with pip
Original Answer
You are using Python 2.5, outdated version:
/Library/Python/2.5/
Please install at least Python 2.7 first:
https://www.python.org/downloads/

Anaconda Python Conda pipbuild failed with WindowsError cannot find file

I recently switched to the Anaconda Python distribution and I'm trying to get the hang of things. I wanted to install this yaml-related package and since there isn't already a conda recipe for it, I tried
conda pipbuild layered-yaml-attrdict-config
which resulted in the following output (I removed non-relevant entries of my system path):
C:\Anaconda>conda install layered-yaml-attrdict-config
Fetching package metadata: ..
Error: No packages found matching: layered-yaml-attrdict-config
C:\Anaconda>conda pipbuild layered-yaml-attrdict-config
Fetching package metadata: ..
Creating standard recipe for layered-yaml-attrdict-config-14.06.7
Using url https://pypi.python.org/packages/source/l/layered-yaml-attrdict-config
/layered-yaml-attrdict-config-14.06.7.tar.gz (6147) for layered-yaml-attrdict-co
nfig.
Downloading layered-yaml-attrdict-config (use --no-download to skip this step)
Unpacking layered-yaml-attrdict-config...
done
working in c:\users\bnables\appdata\local\temp\1\tmp07kkdbconda_skeleton_layered
-yaml-attrdict-config
Fetching package metadata: ...
Solving package specifications: .
The following packages will be downloaded:
package | build
---------------------------|-----------------
python-2.7.7 | 2 17.1 MB
The following packages will be linked:
package | build
---------------------------|-----------------
python-2.7.7 | 2 hard-link
pyyaml-3.11 | py27_0 hard-link
setuptools-3.6 | py27_0 hard-link
Fetching packages ...
python-2.7.7-2 100% |###############################| Time: 0:00:08 2.00 MB/s
Extracting packages ...
[ COMPLETE ] |#################################################| 100%
Linking packages ...
[ COMPLETE ] |#################################################| 100%
Applying patch: u'c:\\users\\bnables\\appdata\\local\\temp\\1\\tmp07kkdbconda_sk
eleton_layered-yaml-attrdict-config\\pypi-distutils.patch'
Error:
Did not find 'patch' in: C:\Anaconda\envs\_build\Scripts;C:\Anaconda\Scripts
;C:\Anaconda;C:\Anaconda\Scripts
You can install 'patch' using apt-get, yum (Linux), Xcode (MacOSX),
or conda, cygwin (Windows),
conda create -n _pipbuild_ --yes python pip
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment C:\Anaconda\envs\_pipbuild_:
The following packages will be linked:
package | build
---------------------------|-----------------
pip-1.5.6 | py27_0 hard-link
python-2.7.7 | 2 hard-link
setuptools-3.6 | py27_0 hard-link
WARNING: the process C:\Anaconda\python.exe C:\Anaconda\Scripts\conda-script.py
pipbuild layered-yaml-attrdict-config (7712) is running
WARNING: the process C:\Anaconda\Scripts\conda-pipbuild.exe layered-yaml-attrdic
t-config (4596) is running
WARNING: the process C:\Anaconda\python.exe C:\Anaconda\Scripts\conda-pipbuild-s
cript.py layered-yaml-attrdict-config (7208) is running
WARNING: Continuing installation while the above processes are running is
not recommended. Please, close all Anaconda programs before installing or
updating things with conda.
Extracting packages ...
[ COMPLETE ] |#################################################| 100%
Linking packages ...
[ COMPLETE ] |#################################################| 100%
#
# To activate this environment, use:
# > activate _pipbuild_
#
C:\Anaconda\envs\_pipbuild_/bin/pip install layered-yaml-attrdict-config==14.06.
7
Traceback (most recent call last):
File "C:\Anaconda\Scripts\conda-pipbuild-script.py", line 4, in <module>
sys.exit(main())
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 76, in
main
args.func(args, p)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 347, i
n execute
build_package(package, version)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 300, i
n build_package
directory, dependencies = make_recipe(package, version)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 244, i
n make_recipe
depends = get_all_dependencies(package, version)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 214, i
n get_all_dependencies
ret = subprocess.Popen(cmd2.split()).wait()
File "C:\Anaconda\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Anaconda\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
C:\Anaconda>
I'm not sure what happened since I don't know what file it was looking for and I don't yet know anything about conda recipes except they're supposed to be awesome and not give these kinda of errors.
I was hoping to install through conda so that everything could be managed by conda instead of some stuff being managed by pip.
Digging into the main_pipbuild.py source it looks like it's trying to run C:\Anaconda\envs\_pipbuild_\bin\pip install package==version (with the appropriate package and version). When I look at my C:\Anaconda\envs_pipbuild_ there is no bin folder, so I'm guessing pip didn't get installed into the pipbuild environment correctly. The previous warnings about not having "patch" may also be a problem...
After installing patch with conda install patch I tried again with the following results:
C:\Anaconda>conda pipbuild layered-yaml-attrdict-config
Fetching package metadata: ..
Creating standard recipe for layered-yaml-attrdict-config-14.06.7
Using url https://pypi.python.org/packages/source/l/layered-yaml-attrdict-config/layered-yaml-attrdict-config-14.06.7.ta
r.gz (6147) for layered-yaml-attrdict-config.
Downloading layered-yaml-attrdict-config (use --no-download to skip this step)
Unpacking layered-yaml-attrdict-config...
done
working in c:\users\bnables\appdata\local\temp\1\tmp7cuibgconda_skeleton_layered-yaml-attrdict-config
Fetching package metadata: ...
Solving package specifications: .69 unparsed bytes left at the end of stream
file 1/1: core.py
hunk no.1 doesn't match source file at line 165
expected:
actual : raise SystemExit, "error: " + str(msg)
source file is different - core.py
Applying patch: u'c:\\users\\bnables\\appdata\\local\\temp\\1\\tmp7cuibgconda_skeleton_layered-yaml-attrdict-config\\pyp
i-distutils.patch'
Traceback (most recent call last):
File "C:\Anaconda\Scripts\conda-skeleton-script.py", line 4, in <module>
sys.exit(main())
File "C:\Anaconda\lib\site-packages\conda_build\main_skeleton.py", line 124, in main
args.func(args, p)
File "C:\Anaconda\lib\site-packages\conda_build\main_skeleton.py", line 135, in execute
pypi.main(args, parser)
File "C:\Anaconda\lib\site-packages\conda_build\pypi.py", line 314, in main
run_setuppy(src_dir, tempdir, args)
File "C:\Anaconda\lib\site-packages\conda_build\pypi.py", line 485, in run_setuppy
apply_patch(join(stdlib_dir, 'distutils'), patch)
File "C:\Anaconda\lib\site-packages\conda_build\source.py", line 202, in apply_patch
check_call([patch, '-p0', '-i', path], cwd=src_dir)
File "C:\Anaconda\lib\subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '[u'C:\\Anaconda\\Scripts\\patch.bat', u'-p0', u'-i', u'c:\\users\\bnables\\appda
ta\\local\\temp\\1\\tmp7cuibgconda_skeleton_layered-yaml-attrdict-config\\pypi-distutils.patch']' returned non-zero exit
status -1
conda create -n _pipbuild_ --yes python pip
Error: prefix already exists: C:\Anaconda\envs\_pipbuild_
C:\Anaconda\envs\_pipbuild_/bin/pip install layered-yaml-attrdict-config==14.06.7
Traceback (most recent call last):
File "C:\Anaconda\Scripts\conda-pipbuild-script.py", line 4, in <module>
sys.exit(main())
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 76, in main
args.func(args, p)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 347, in execute
build_package(package, version)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 300, in build_package
directory, dependencies = make_recipe(package, version)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 244, in make_recipe
depends = get_all_dependencies(package, version)
File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 214, in get_all_dependencies
ret = subprocess.Popen(cmd2.split()).wait()
File "C:\Anaconda\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Anaconda\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
So it finds some kind of problem with the package perhaps at Solving package specifications: .69 unparsed bytes left at the end of stream. Then it does this patch thing which apparently fails. Then it tries to do pip install and again can't find the bin/pip directory in the pipbuild environment.
Should it be looking for pip at C:\Anaconda\envs\_pipbuild_\Scripts\pip.exe? Because that does exist.
If this is a bug, here's where to report it: https://github.com/conda/conda-build/issues. I'll wait for feedback before doing any more.
Any help would be great!
I've had similar issues when trying to build PyPI packages with "conda pipbuild package-name", and I wasn't able to get it running on Windows 7 (x64). One useful workaround that I've found (if you want to install the package with "conda install package-name", into a specific conda environment) is as follows:
Install the PyPI package with "pip install package-name"
Upload the package to your binstar account with "binstar upload %conda_install_path%/pkgs/package-name-ver-py27.tar.bz2"
Install the package into a specific conda env with "conda install -c https://conda.binstar.org/user-name package-name -p %path-to-conda-env%"
There is a fix for the same issue on Python 3 at https://groups.google.com/a/continuum.io/d/msg/anaconda/6_reeaIjx5c/fhRjbA4AdQkJ. It involves editing the distutils\cygwinccompiler.py file in the Python standard library.
I think you can do the same thing in Python 2, though it may require some translation, as the Python 2 version of cygwinccompiler uses os.popen instead of subprocess.check_output. Assumedly you can just use subprocess.check_output(['gcc', '-dumpmachine'], shell=True) in the relevant place in the file and it will fix the issue.

Categories

Resources