how can I install yarl in Docker? - python

I get the following Runtime error when running my dockerfile.
"yarl 1.4+ requires Python 3.5+"
This happens when Docker tries to install the slackclient requirement for my image.
I already have python 3.8 installed on my machine.
What am I doing wrong?
Here is the dockerfile:
FROM ubuntu:trusty
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get update && \
apt-get -y install \
python3 \
python3-pip \
make \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
zip \
git-core \
supervisor \
sqlite
RUN mkdir -p /tmp
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install -r /tmp/requirements.txt
COPY deployment/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN mkdir -p /opt/wwc
ADD . /opt/wwc/apartment-finder
RUN mkdir -p /opt/wwc/logs
WORKDIR /opt/wwc/apartment-finder
CMD ["/usr/bin/supervisord"]
Here is the full error message:
Running setup.py (path:/tmp/pip_build_root/yarl/setup.py) egg_info for package yarl
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/yarl/setup.py", line 10, in <module>
raise RuntimeError("yarl 1.4+ requires Python 3.5+")
RuntimeError: yarl 1.4+ requires Python 3.5+
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/yarl/setup.py", line 10, in <module>
raise RuntimeError("yarl 1.4+ requires Python 3.5+")
RuntimeError: yarl 1.4+ requires Python 3.5+

The version of python you have on your machine is not relevant to the problem. The problem is the version of python within the container you are trying to build. The container does not have access to your system's python.
Ubuntu Trusty Tahr is also known as 14.04. You can treat this version like a date -- this came out in April 2014. You shouldn't use 14.04 because it reached its end-of-life. Also, python 3.5 came out in September 2015 -- after the release of 14.04.
The solution, then, is to use a newer base image. You have many choices, but if you want to stick to ubuntu, then you can use the latest long-term-support (LTS) version, 20.04. To do this, change your FROM instruction to FROM ubuntu:20.04. Ubuntu 20.04 uses Python 3.8.

Related

awscli fails to execute within python virtual environment

I'm really bad with python. This is on a CentOS7 vm
Problem:
When trying to use awscli in a python virtual environment, I get an error:
(python3ve) [user#ncwv-jlnxnode01 ~]$ aws --version
Traceback (most recent call last):
File "/home/user/venv/python3ve/bin/aws", line 27, in
sys.exit(main())
File "/home/user/venv/python3ve/bin/aws", line 23, in main
return awscli.clidriver.main()
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/clidriver.py", line 69, in main
driver = create_clidriver()
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/clidriver.py", line 79, in create_clidriver
event_hooks=session.get_component('event_emitter'))
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/plugin.py", line 44, in load_plugins
modules = _import_plugins(plugin_mapping)
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/plugin.py", line 61, in _import_plugins
module = __import__(path, fromlist=[module])
ModuleNotFoundError: No module named '/root/'
ultimately i'm trying to put together a step by step method in an ansible playbook for not only installing awscli, but also awscli-plugin-endpoint, so i'd prefer to install this through pip instead of the centos repos and instead of just downloading the binaries.
Installation Steps:
remove python3 and everything python3 related on the system.
~$ rm -rf ~/venv/python3ve/
~$ sudo yum remove -y python3
~$ sudo yum autoremove -y
~$ sudo find / -name "python3*" > ~/file
~$ sudo xargs rm -r ~/file (missing the arrow because stackoverflow formatting is freaking out with it)
install
~$ sudo yum install -y python3
~$ /usr/bin/python3 -m venv ~/venv/python3ve
~$ source ~/venv/python3ve/bin/activate
~$ ~/venv/python3ve/bin/python3 -m pip install --upgrade pip
~$ ~/venv/python3ve/bin/python3 -m pip install --upgrade awscli
~$ which aws
~/venv/python3ve/bin/aws
~$ aws --version
---output is in the problem description above---
suggestions?
ultimately found that the error was stemming from my ~/.aws/config which I wasnt removing when I reinstalled. that had a reference to the plugin not yet installed and also the old site-packages path (pre venv)
cli_legacy_plugin_path=/root/.local/lib/python3.6/site-packages/
endpoint = awscli_plugin_endpoint
Once I removed those, it worked fine again.
~$ aws --version
aws-cli/1.24.10 Python/3.6.8 Linux/3.10.0-957.el7.x86_64 botocore/1.26.10
The error was referencing /root/ because of how _import_plugins within /awscli/plugin.py splits the path based on . if present
module = path.rsplit('.', 1)

How can I correctly install & run pip in a wine-emulated python version (inside a docker container)?

I wanted to do a MetaTrader5 environment with Python. While I could do it in my Windows machine, I'd like to have it as a standalone Docker container to, say, deploy in my (I have two other systems that I prefer for coding: mac and linux) machine or perhaps an AWS ECR.
For that purpose, I created this docker file:
FROM ubuntu:20.04
# In order to use the python version, we'll have to install
# wine emulator. We're installing both 32 and 64 bits API.
RUN dpkg --add-architecture i386
RUN apt update
ENV TZ=UTC
RUN apt-get install --assume-yes apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes tzdata
RUN apt-get install --assume-yes wine64 wine32
# The root wine prefix will be: /root/.wine.
# Now MetaTrader5 is being moved to the Program Files directory.
COPY ["MetaTrader5", "/root/.wine/drive_c/Program Files/MetaTrader5"]
# Also the Python interpreter is moved to that directory.
ADD ["python-3.9.0", "/root/.wine/drive_c/Program Files/python-3.9.0"]
# And the get-pip script is added to the standard interpreter.
ADD ["https://bootstrap.pypa.io/get-pip.py", "/root/.wine/drive_c/Program Files/python-3.9.0/get-pip.py"]
# The server script itself is then added as another application.
RUN ["mkdir", "-p", "/root/.wine/drive_c/Program Files/MetaTrader5 AI Server"]
COPY ["server.py", "/root/.wine/drive_c/Program Files/MetaTrader5 AI Server/server.py"]
############### 'Till this point, everything is fine.
# Now, pip will be installed for windows.
RUN ["wine", "/root/.wine/drive_c/Program Files/python-3.9.0/pythonw.exe", "/root/.wine/drive_c/Program Files/python-3.9.0/get-pip.py"]
# And then, metatrader will be installed, along with aiohttp
# library for websockets.
# RUN pip install MetaTrader5 aiohttp
# Choosing this tail command is just for debug
# purposes, as the true implementation will use
# the server.py file as entry point.
CMD ["tail", "-f", "/dev/null"]
The issue I'm having involves the last part: When get-pip.py is executed, the Scripts/ directory (/root/.wine/drive_c/Program Files/python-3.9.0/Scripts) is created with the pip.exe and easy_install.exe executables, but when trying to invoke either of them, an error is raised, as the pip python module does not seem to be installed.
This can be tested by running this dockerfile:
$ docker build . --tag=mt5pyserver
$ docker run --name=prueba -it mt5pyserver bash
And then:
root#a169a4c4aae8:~# cd ".wine/drive_c/Program Files/python-3.9.0"
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine python.exe get-pip.py
Collecting pip
Using cached pip-20.2.3-py2.py3-none-any.whl (1.5 MB)
Collecting setuptools
Using cached setuptools-50.3.0-py3-none-any.whl (785 kB)
Collecting wheel
Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: pip, setuptools, wheel
WARNING: The scripts pip.exe, pip3.9.exe and pip3.exe are installed in 'C:\Program Files\python-3.9.0\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts easy_install-3.9.exe and easy_install.exe are installed in 'C:\Program Files\python-3.9.0\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script wheel.exe is installed in 'C:\Program Files\python-3.9.0\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.2.3 setuptools-50.3.0 wheel-0.35.1
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# pip
bash: pip: command not found
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine Scripts/pip.exe
Traceback (most recent call last):
File "runpy.py", line 197, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "C:\Program Files\python-3.9.0\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine --version
wine-5.0 (Ubuntu 5.0-3ubuntu1)
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0#
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine Scripts/pip.exe
Traceback (most recent call last):
File "runpy.py", line 197, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "C:\Program Files\python-3.9.0\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0#
What I need is to correctly install pip in the in-windows python interpreter. There is an underlying reason: package MetaTrader5 only exists for windows python versions. In the end, I'd like to install that package and also aiohttp. The server will then make use of those packages as described in the MetaTrader5 documentation for Python integration and some magic on my own.
What can I do to avoid getting that error?
Have a look at this Dockerfile. It might give you some insight. The approach used is completely different.
Some noteworthy differences between this Dockerfile and your setup:
Use wine from the WineHQ's package repository, not Ubuntu's.
Download python msi setup files from python.org and install them using wine msiexec.
Here's an except from the Dockerfile:
...
...
ARG PYINSTALLER_VERSION=4.0
...
...
RUN set -x \
&& for msifile in `echo core dev exe lib path pip tcltk tools`; do \
wget -nv "https://www.python.org/ftp/python/$PYTHON_VERSION/amd64/${msifile}.msi"; \
wine msiexec /i "${msifile}.msi" /qb TARGETDIR=C:/Python37; \
rm ${msifile}.msi; \
done \
&& cd /wine/drive_c/Python37 \
&& echo 'wine '\''C:\Python37\python.exe'\'' "$#"' > /usr/bin/python \
&& echo 'wine '\''C:\Python37\Scripts\easy_install.exe'\'' "$#"' > /usr/bin/easy_install \
&& echo 'wine '\''C:\Python37\Scripts\pip.exe'\'' "$#"' > /usr/bin/pip \
&& echo 'wine '\''C:\Python37\Scripts\pyinstaller.exe'\'' "$#"' > /usr/bin/pyinstaller \
&& echo 'wine '\''C:\Python37\Scripts\pyupdater.exe'\'' "$#"' > /usr/bin/pyupdater \
&& echo 'assoc .py=PythonScript' | wine cmd \
&& echo 'ftype PythonScript=c:\Python37\python.exe "%1" %*' | wine cmd \
&& while pgrep wineserver >/dev/null; do echo "Waiting for wineserver"; sleep 1; done \
&& chmod +x /usr/bin/python /usr/bin/easy_install /usr/bin/pip /usr/bin/pyinstaller /usr/bin/pyupdater \
&& (pip install -U pip || true) \
&& rm -rf /tmp/.wine-*
ENV W_DRIVE_C=/wine/drive_c
ENV W_WINDIR_UNIX="$W_DRIVE_C/windows"
ENV W_SYSTEM64_DLLS="$W_WINDIR_UNIX/system32"
ENV W_TMP="$W_DRIVE_C/windows/temp/_$0"
# install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 dll files
RUN set -x \
&& rm -f "$W_TMP"/* \
&& wget -P "$W_TMP" https://aka.ms/vs/16/release/vc_redist.x64.exe \
&& cabextract -q --directory="$W_TMP" "$W_TMP"/vc_redist.x64.exe \
&& cabextract -q --directory="$W_TMP" "$W_TMP/a10" \
&& cabextract -q --directory="$W_TMP" "$W_TMP/a11" \
&& cd "$W_TMP" \
&& rename 's/_/\-/g' *.dll \
&& cp "$W_TMP"/*.dll "$W_SYSTEM64_DLLS"/
# install pyinstaller
RUN /usr/bin/pip install pyinstaller==$PYINSTALLER_VERSION
...
...
Also, why do you have to install pip when Python 2 >=2.7.9 or Python 3 >=3.4 already includes pip?
Further note that it is recommended to put related commands (apt-get update/install) in the same RUN step.

Install GDAL/OGR Python API on Debian

I trying to install Python GDAL/OGR bindings to be accessible directly from Python interpreter on Docker python:3.6-stretch image.
My Dockerfile looks like that:
FROM python:3.6-stretch
ENV PYTHONUNBUFFERED 1
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update && apt-get install -y \
binutils \
libproj-dev \
gdal-bin \
libgdal-dev \
python3-gdal \
python3-pip \
python-numpy \
python-dev \
vim
COPY . /app
RUN pip3 install --no-cache-dir -r /app/requirements.txt \
&& rm -rf /requirements.txt
WORKDIR /app
Dockerfile installs current stable version of GDAL and python3-gdal which is 2.1.2.
Import osgeo from Python interpreter gives me an error:
>>> from osgeo import gdal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'osgeo'
How to install neccessary libs properly?
Check if you are using correct python 3 interpreter. You can call in linux system:
whereis python3
You had install python3-pip package, so you have osgeo in your main python 3 in /usr/bin/python3. In other python 3 locations osgeo can be not available.
I solved this problem by installing via Python PIP pygdal package. Firstly you need to check Gdal version installed on the machine, and install proper pygdal.
$ gdalinfo --version
GDAL 2.1.3, released 2017/20/01
$ pip install "pygda>=2.1.2,<2.1.3"

Error in installing PyQt

I am following this manual for installing PyQt in Mac but I got the following error:
Monas-MacBook-Pro:sip-4.16.7 mona$ sudo make install
Password:
cp -f sip /Library/Frameworks/Python.framework/Versions/3.4/bin/sip
cp -f sip.so /Library/Python/3.3/site-packages/sip.so
cp -f /Users/mona/OpenSource/sip-4.16.7/siplib/sip.h /Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m/sip.h
cp -f sipconfig.py /Library/Python/3.3/site-packages/sipconfig.py
cp -f /Users/mona/OpenSource/sip-4.16.7/sipdistutils.py /Library/Python/3.3/site-packages/sipdistutils.py
Monas-MacBook-Pro:sip-4.16.7 mona$ cd ..
Monas-MacBook-Pro:OpenSource mona$ ls
PyQt-mac-gpl-4.11.3 sip-4.16.7
PyQt-mac-gpl-4.11.3.tar.gz sip-4.16.7.tar.gz
Monas-MacBook-Pro:OpenSource mona$ cd PyQt-mac-gpl-4.11.3
Monas-MacBook-Pro:PyQt-mac-gpl-4.11.3 mona$ python3 configure.py -d /Library/Python/3.3/site-packages/ --use-arch x86_64
Traceback (most recent call last):
File "configure.py", line 32, in <module>
import sipconfig
ImportError: No module named 'sipconfig'
Any idea how to fix it?
To get the new version of pyqt wich is pyqt5, you start by installing a version of python 3.5 https://www.python.org/downloads/release/python-350/
And you can run the command line: pip3 install pyqt5 (sometimes you will need to write it in the correct format so it will look like : pip3 install PyQt5)
Otherwise you can use brew, first install brew :/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
And when it's done. run : brew install pyqt
It should work

mysqlfailover: No module named mysql.utilities.common.tools

I am trying to setup mysqlfailover utility on ec2 instance running Ubuntu 12.04. I performed the following steps:
Downloaded mysql-connector-python:
wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python_1.0.12-1debian6.0_all.deb -o mysql-connector-python_1.0.12-1debian6.0_all.deb
(Installed using dpkg -i command.)
Download mysql-utilities:
wget http://cdn.mysql.com/Downloads/MySQLGUITools/mysql-utilities_1.3.5-1debian6.0_all.deb -o mysql-utilities_1.3.5-1debian6.0_all.deb
(Installed using dpkg -i command.)
There were some dependencies issues. I ran the following commands:
sudo apt-get install python-pip
easy_install -U distribute
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
pip install mysql-python
Now, when I run the command mysqlfailover, it gives the following error:
Traceback (most recent call last):
File "/usr/bin/mysqlfailover", line 24, in <module>
from mysql.utilities.common.tools import check_python_version
ImportError: No module named mysql.utilities.common.tools
I have been banging my head around quite some time now, but no success. Any help in the matter is highly appreciated. Thanks.
Try env PYTHONPATH=/usr/share/pyshared/ mysqlfailover
Thers is no utilities in mysql modul, you can check this do:
ls /usr/lib/python2.7/dist-packages/mysql
So you should change mysql package:
cp -r /usr/share/pysharedmysql /usr/lib/python2.7/dist-packages/mysql

Categories

Resources