pipenv problem getting MarkupSafe to automatically install as a dependency - python-3.x

I'm using #arocks DjangoPatternsBook and code.
I have the book and would like to follow along with the code, but I think I found a bug because it's failing for me right at the starting line on two different computers using different python environments, so I don't think it's my environment that's causing the problem.
From the book section Starting the project:
First, clone the example project from GitHub:
$ git clone https://github.com/DjangoPatternsBook/superbook2.git
Next, install pipenv system-wide [this is what I did, using brew on MacOS and using dnf on Fedora 32] or locally, but outside a virtualenv as recommended in pipenv installation documents. Alternatively, follow these commands [I did not do this]:
$ pip install -U pip
$ pip install pipenv
Now go to the project directory and install the dependencies:
$ cd superbook2
$ pipenv install --dev
This is where it fails for me with the message:
[pipenv.exceptions.InstallError]: ['Looking in indexes: https://pypi.python.org/simple', 'Collecting markupsafe==1.0', ' Using cached MarkupSafe-1.0.tar.gz (14 kB)']
[pipenv.exceptions.InstallError]: ['ERROR: Command errored out with exit status 1:', ' command: /home/alpha/.local/share/virtualenvs/superbook2-HNnQDu9M/bin/python3 -c \'import sys, setuptools, tokenize; sys.argv[0] = \'"\'"\'/tmp/pip-install-5kl59pd3/markupsafe/setup.py\'"\'"\'; __file__=\'"\'"\'/tmp/pip-install-5kl59pd3/markupsafe/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' egg_info --egg-base /tmp/pip-pip-egg-info-bk6ldht4', ' cwd: /tmp/pip-install-5kl59pd3/markupsafe/', ' Complete output (5 lines):', ' Traceback (most recent call last):', ' File "<string>", line 1, in <module>', ' File "/tmp/pip-install-5kl59pd3/markupsafe/setup.py", line 6, in <module>', ' from setuptools import setup, Extension, Feature', " ImportError: cannot import name 'Feature' from 'setuptools' (/home/alpha/.local/share/virtualenvs/superbook2-HNnQDu9M/lib/python3.8/site-packages/setuptools/__init__.py)", ' ----------------------------------------', 'ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.']
ERROR: ERROR: Package installation failed...
So on a newly installed Fedora 32 machine, I did only:
$ sudo dnf install git
$ sudo dnf install pipenv
$ git clone https://github.com/DjangoPatternsBook/superbook2.git
$ cd superbook2
$ pipenv install --dev
and I think this same (or similar) sequence of commands will fail similarly in other python environments.
Does anyone have any suggestions on how to work around this problem and move forward with the code examples in the book? I've already posted a new issue in the github repo for superbook2 although I suspect the problem lies outside the superbook2 code base because I see other similar issues unrelated to superbook2.
I'll gladly post output of pipenv --support if it would help. The two python environments were using versions 3.8.3 (Fedora) and 3.8.5 (MacOS).

Related

distutils.errors.DistutilsError: Command . . . returned non-zero exit status 1 [duplicate]

Here are the commands I am running:
$ python setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: invalid command 'bdist_wheel'
$ pip --version
pip 1.5.6 from /usr/local/lib/python3.4/site-packages (python 3.4)
$ python -c "import setuptools; print(setuptools.__version__)"
2.1
$ python --version
Python 3.4.1
$ which python
/usr/local/bin/python
Also, I am running a mac with homebrewed python
Here is my setup.py script:
https://gist.github.com/cloudformdesign/4791c46fe7cd52eb61cd
I'm going absolutely crazy -- I can't figure out why this wouldn't be working.
Install the wheel package first:
pip install wheel
The documentation isn't overly clear on this, but "the wheel project provides a bdist_wheel command for setuptools" actually means "the wheel package...".
I also ran into the error message invalid command 'bdist_wheel'
It turns out the package setup.py used distutils rather than setuptools.
Changing it as follows enabled me to build the wheel.
#from distutils.core import setup
from setuptools import setup
Update your setuptools, too.
pip install setuptools --upgrade
If that fails too, you could try with additional --force flag.
I also ran into this all of a sudden, after it had previously worked, and it was because I was inside a virtualenv, and wheel wasn’t installed in the virtualenv.
Update your pip first:
pip install --upgrade pip
for Python 3:
pip3 install --upgrade pip
Throwing in another answer: Try checking your PYTHONPATH.
First, try to install wheel again:
pip install wheel
This should tell you where wheel is installed, eg:
Requirement already satisfied: wheel in /usr/local/lib/python3.5/dist-packages
Then add the location of wheel to your PYTHONPATH:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.5/dist-packages/wheel
Now building a wheel should work fine.
python setup.py bdist_wheel
It could also be that you have a python3 system only.
You therefore have installed the necessary packages via pip3 install , like pip3 install wheel.
You'll need to build your stuff using python3 specifically.
python3 setup.py sdist
python3 setup.py bdist_wheel
Cheers.
I tried everything said here without any luck, but found a workaround.
After running this command (and failing) : bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Go to the temporary directory the tool made (given in the output of the last command), then execute python setup.py bdist_wheel. The .whl file is in the dist folder.

ModuleNotFoundError: No module named 'uaclient.entitlements' dpkg: error processing package ubuntu-advantage-tools (--configure):

Whenever i try sudo apt-get upgrade or try to install any other package i get the above error. Is there any way to solve it?? Using ubuntu 16.04
Removing python3-distro-info (0.14ubuntu0.2) ...
Setting up ubuntu-advantage-tools (27.0~16.04.1) ...
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'uaclient.entitlements'
dpkg: error processing package ubuntu-advantage-tools (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
ubuntu-advantage-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)
You should install opcua and opcua-client with default python command:
python -m pip install --upgrade opcua
python -m pip install --upgrade opcua-client
I have the same problem and try to solve then it work for me.
My environment:
OS: ubuntu 18.04 LTS
python version: 3.6.9(system default) , manual
install 3.8.7
System python path have been link to python 3.8 when I install python 3.8, so any process use python will call python 3.8 and use pip3.8 site-packages, not use system dist-packages(python 3.6). But python 3.8 uaclinet(install by pip) is different from uaclinet in dist-packages(ubuntu-advantage-tools provide). then I use apt upgrade
設定 ubuntu-advantage-tools (27.0.2~18.04.1) ...
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'uaclient.entitlements'
dpkg: error processing package ubuntu-advantage-tools (--configure):
installed ubuntu-advantage-tools package post-installation script subprocess returned error exit status 1
處理時發生錯誤:
ubuntu-advantage-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)
So, I copy the uaclinet(in dist-packages) to python 3.8 site-packages and run upgrade again, then it works( maybe has compatibility problems )
設定 ubuntu-advantage-tools (27.0.2~18.04.1) ...
W: APT had planned for dpkg to do more than it reported back (0 vs 4).
Affected packages: ubuntu-advantage-tools:amd64
I think if your use system python , you can use comment by Jan Wilamowski,
This problem appeared for me after upgrading to Ubuntu 18.04 from 16.04.
I updated opcua and opcua-client as suggested with python -m pip install, and also with pip3 install, to get it updated in python3 packages, and the problem remained.
I have system python3 installed in /usr/bin/python3 (version 3.6), and another version in /usr/local/bin/python3 (version 3.8) which is the default python3. I'm not sure why, but the uaclient.entitlements module can be loaded properly with /usr/bin/python3, but not with /usr/local/bin/python3
Instead of changing the location of the uaclient package, the following worked for me:
I used update-alternatives to choose which python3 will be used by default, either system python3 which is /usr/bin/python3.6, or the updated python3 which is installed in /usr/local/bin/python3.8 as described here:
https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/local/bin/python3 python3 /usr/local/bin/python3.8 2
Then, choose /usr/bin/python3.6 as the default by running:
sudo update-alternatives --config python3
A symlink is created as /etc/alternatives/python3 that points to the chosen default python3.
Since the way I set the alternatives results in /usr/local/bin/python3.8 as the automatic default python3, the symlink /usr/bin/python3 -> python3.6 is removed. But this symlink is still needed for dependencies/functions that use system python through /usr/bin/python3, so I added back the sym link:
sudo ln -s python3.6 /usr/bin/python3
By setting /usr/bin/python3.6 as the default instead of /usr/local/bin/python3.8, then uaclient.entitlements can be loaded properly. This worked for me to install and upgrade packages where this uaclient.entitlements ModuleNotFoundError was occurring. Just have to switch back to using /usr/local/bin/python3.8 when finished installing. But I think now that ubuntu-advantage-tools is configured by getting through this error, there doesn't seem to be a need to switch to /usr/bin/python3.6 as the default anymore for installing packages.
The answer in https://askubuntu.com/questions/1336425/no-module-named-uaclient-during-sudo-apt-upgrade-ubuntu-16-04 worked for me. Basically, I modified manually the post-installation and pre-remove script in /var/lib/dpkg/info/ubuntu-advantage-tools.postinst and /var/lib/dpkg/info/ubuntu-advantage-tools.prerm and replace python3 with the complete path /usr/bin/python3.5, and then the 'apt-get upgrade' didn't fail as before.
If you are not going to use ubuntu advantage tools then
sudo dpkg --remove --force-remove-reinstreq ubuntu-advantage-tools
but even tat failed for me... I had to
sudo rm /var/lib/dpkg/info/ubuntu-advantage-tools.prerm
because this script was blocking uninstall
i have tried to install:
python -m pip install --upgrade opcua
python -m pip install --upgrade opcua-client
but even that was failing for me on a second - client installation
finally after about 6 months I can do ubuntu update without error reporting.

Unable to install bottle-memcache in ubuntu using pip3 with python3.6 [duplicate]

I have installed pip for python 3.6 on Ubuntu 14. After I run
sudo apt-get install python3-pip
to install pip3, it works very well. However, after installation, when I am trying to run
pip3 install packagename
to install a new package, something strange occurs:
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1479, in <module>
register_loader-type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module "importlib._bootstrap" has no attribute "SourceFileLoader"
It seems that I did nothing wrong, and I really cannot figure out the reason.
If you're getting this error running pip install dotenv, this is because the package is called python-dotenv not dotenv.
This worked for me:
sudo pip install python-dotenv
Faced the same problem. I think this is because python3.6 and pip3 were installed from different sources.
I suggest using python's inbuilt facility to install pip i.e
python3 -m ensurepip --upgrade
This should install pip3 and pip3.x where x in python3.x.
Same works for python2 also.
Tried to install Tensorflow in venv on Windows 10 machine with python 3.8 and got the same issue.
What helped for me was:
pip install setuptools --upgrade
I had the same problem on my ubuntu 18.04 with python 3.6. None of the above methods helped, but this one solved the problem:
pip3 uninstall setuptools
I had the same error whatever I asked to pip. I gave a look to this page: https://packaging.python.org/tutorials/installing-packages/
That line is the one that solved my problem:
python3 -m pip install --upgrade pip setuptools wheel
pip install setuptools --upgrade
This command solved my issue. It fixed my problem.
When updating from python3.4 to python3.6 on ubuntu 14.04. The following solved me:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3
If you face this issue in anaconda environment, simply upgrade setuptools using the following:
conda install -c conda-forge setuptools
That's because you are using an old version of setuptools, check up this issue.
I met the same problem, this is the key:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3
I had faced the same issue on Ubuntu 19.10 and now I upgraded to Ubuntu 20.04 and faced the issue again. This issue is due to broken pip3. So whenever you enter pip3 and hit enter it will show the same error. So instead of using "pip3 uninstall setuptools" use the below code
python3 -m pip uninstall setuptools
It resolved my issue 3rd time
I am facing the same problem, which is solved by downloading the source files of the setuptools and installing the module manually.
The setuptools can be downloaded here:
https://pypi.org/project/setuptools/
After downloading, unzip the package first, then cd to the directory and run
python setup.py install --user
For me the error happened while trying to create a virtual env with python 3.8:
sudo virtualenv venv -ppython3.8
And after trying all the answers here, finally the problem solved by installing the new version of virtualenv (20.0.7):
sudo pip3 install virtualenv
I encountered this error message triggered by a slightly different situation which I'll mention here for anyone who finds this.
This same error also occurs when installing the distribute Python package (which is currently just a compatibility layer in front of setuptools) in Python 3.6 or newer.
In my specific situation I discovered this as I was using pyzmail which has been somewhat abandoned and depends on distribute.
Collecting distribute
Downloading distribute-0.7.3.zip (145 kB)
ERROR: Command errored out with exit status 1:
command: /var/lang/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-hgbjn0js
cwd: /tmp/pip-install-ssqyqflj/distribute/
Complete output (15 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/dist.py", line 7, in <module>
from setuptools.command.install import install
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/__init__.py", line 8, in <module>
from setuptools.command import install_scripts
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/install_scripts.py", line 3, in <module>
from pkg_resources import Distribution, PathMetadata, ensure_directory
File "/tmp/pip-install-ssqyqflj/distribute/pkg_resources.py", line 1518, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
I had the same issue when I tried to install the Slate package in Windows 10, Python 3.7.4 version:
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
The instruction that generated the error:
C:\WINDOWS\system32>python -m pip install slate
The instruction that worked:
C:\WINDOWS\system32>python -m pip install https://github.com/timClicks/slate/archive/master.zip
I had the same problem with my cloud computer. If all above didn't work for you don't worry. Here's how I resolved it:
Download the pip file (pip-version.tar.gz) from:
https://pypi.org/project/pip/#files
For cloud, use this
curl https://files.pythonhosted.org/packages/8e/76/66066b7bc71817238924c7e4b448abdb17eb0c92d645769c223f9ace478f/pip-20.0.2.tar.gz --output pip.tar.gz
Extract the content of the file and cd into the directory.
Run the following in the directory
python3 setup.py install --user
You should have pip3 working without errors.
pip3 install setuptools --upgrade
This also cured the issue on Python 3.9 running on Windows 10 and even on a custom Docker image.
I was having the same issue while using docker-compose. This exact error can be caused by not being the root user. Running the same commands with sudo fixed it for me. I don't not have setup-tools installed, and I'm running pip3. My issue was that IntelliJ didn't have sudo rights, so i had to do it from the terminal.
Above solutions were not working in my case for Ubuntu 20
If you run the following command:
sudo apt install python3-setuptools
Then you might get the result:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-setuptools is already the newest version (45.2.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
But to actually solve it and re-install setuptools try following commands:
sudo apt download python3-setuptools
sudo dpkg -i python3-setuptools_45.2.0-1_all.deb
Note: Change the version of the python package that is downloaded
Traceback (most recent call last):
File "/usr/bin/pipenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/myuser/.local/lib/python3.7/site-packages/pkg_resources.py", line
1479, in <module>
Mine looked pretty similar, but for some reason I had a python installation in my home directory .local folder.
I did some of the other answers in this thread to ensure I had good local copy of python, then did:
rm -rf ~/.local
Just go inside the /usr/lib/python3/dist-packages/, first copy setuptools file somewhere and then delete the setuptools. Everything will be okay for deleting you can use:
sudo rm -r setuptools
for copying
sudo cp -r setuptools /...Desktop/
After that if it gives errors just:
sudo pip3 install setuptools==3.8.1
to download again.

How do you install something directly from the GitHub repo?

I am a beginner, and tried to install PyDictionary with pip. It installed, but I had the same issue as this thread - it did not work:
How to get rid of the BeautifulSoup html parser error when I'm not using BeautifulSoup
Someone on here suggested installing if directly from the GitHub repo, but I'm not sure which file to download and what to do next.
UPDATE 1
I've updated pip, and used:
python3 -m pip install PyDictionary
(I needed python3 for some reason). I then used this program:
from PyDictionary import PyDictionary
dictionary = PyDictionary()
print (dictionary.synonym("Life"))
But got:
Warning (from warnings module): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PyDictionary/utils.py", line 5 return BeautifulSoup(requests.get(url).text) UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
The code that caused this warning is on line 5 of the file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PyDictionary/utils.py.
To get rid of this warning, pass the additional argument 'features="lxml"' to the BeautifulSoup constructor. Life has no Synonyms in the API None –
UPDATE 2
python3 -m pip install git+https://github.com/geekpradd/PyDictionary
returns:
Collecting git+github.com/geekpradd/PyDictionary Cloning github.com/geekpradd/PyDictionary to /private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxt Running command git clone -q github.com/geekpradd/PyDictionary /private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxtERROR: Command errored out with exit status 1: command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxt/setup.py'"'"'; file__='"'"'/private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxt/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxt/pip-egg-info cwd: /private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxt/ Complete output (5 lines): Traceback (most recent call last):
File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tokenize.py", line 392, in open buffer = _builtin_open(filename, 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/sn/081bt1wd0d3gy2styt2_l1vw0000gn/T/pip-req-build-73cegdxt/setup.py'
---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output
You can normally install directly using the github repos with
python3 -m pip install git+https://github.com/geekpradd/PyDictionary
But this repository has no setup.py file that's why it fails.
To me it's more likely a problem with conflicting python versions, so:
python3 -m pip install PyDictionary
Is enough
See VCS, from the pip docs
pip currently supports cloning over git, git+http, git+https, git+ssh, git+git and git+file:
Here are the supported forms:
git://git.example.com/MyProject#egg=MyProject
git+http://git.example.com/MyProject#egg=MyProject
git+https://git.example.com/MyProject#egg=MyProject
git+ssh://git.example.com/MyProject#egg=MyProject
git+git://git.example.com/MyProject#egg=MyProject
git+file:///home/user/projects/MyProject#egg=MyProject

Error installing Firefox 'marionette_driver' python package

Error installing Mozilla automation client 'marionette_driver'.
Mozilla documentation says to install with the following command:
$ pip install marionette_driver
This produces an error:
Collecting marionette_driver
Downloading marionette_driver-2.2.0.tar.gz
Collecting mozrunner>=6.13 (from marionette_driver)
Downloading mozrunner-6.13.tar.gz (67kB)
100% |████████████████████████████████| 71kB 1.5MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-0829rk11/mozrunner/setup.py", line 24, in
<module>
assert sys.version_info[0] == 2
AssertionError
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
/tmp/pip-build-0829rk11/mozrunner/
These variations of the pip install command produce the same error.
$ sudo pip install marionette_driver
$ sudo -H pip install marionette_driver
$ pip3 install marionette_driver
$ sudo pip3 install marionette_driver
$ sudo -H pip3 install marionette_driver
(debian systems seem to require pip3 to install python3 packages, while it has been suggested the egg_info error can be avoided by using sudo -H. seems to make no difference.)
I have both Python 2.7 and 3.5 installed. I would normally expect pip to install python 2 packages. But I use 3.5, so what do I know? Anyway, the same error occurs using pip and pip3.
The error occurs when you install the mozrunner dependency of marionette_driver. The error message indicates that it is checking that it is running on Python version 2.x (assert sys.version_info[0] == 2), which fails as you would expect. Unfortunately, at time of writing, there is not Python 3 compatible version of mozrunner, so it looks like you will not be able to install marionette_driver for Python 3.
If you are using virtual environments (e.g. with virtualenv, anaconda, or similar), you should be able to create a Python 2 environment and install it there with pip.
Also, on most Unix-like systems, you can install both Python 2 and 3. Usually, the executables will be called python2 and python3, with one of them sym-linked to the default python. The same goes for the corresponding pip2 and pip3 executables. You may have better luck running your installation via pip2, if you have Python 2 installed on your system.

Resources