Collecting ansible Downloading https://files.pythonhosted.org/packages/e8/b2/c10b82573bb494d9e0764b5c75eb7be1e649082435280f2220976d1a3b33/ansible-2.9.11.tar.gz (14.2MB) 100% |████████████████████████████████| 14.3MB 94kB/s Saved ./ansible-2.9.11.tar.gz Collecting PyYAML (from ansible) Downloading https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz (269kB) 100% |████████████████████████████████| 276kB 1.1MB/s Saved ./PyYAML-5.3.1.tar.gz Collecting cryptography (from ansible) Downloading https://files.pythonhosted.org/packages/26/d6/e8b087b9ae062d737c67c3bf76e30333bda9295ca17205062e8ed2c872de/cryptography-3.0-cp35-abi3-manylinux1_x86_64.whl (2.7MB) 100% |████████████████████████████████| 2.7MB 368kB/s Saved ./cryptography-3.0-cp35-abi3-manylinux1_x86_64.whl Collecting jinja2 (from ansible) Downloading https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl (125kB) 100% |████████████████████████████████| 133kB 2.2MB/s Saved ./Jinja2-2.11.2-py2.py3-none-any.whl Collecting six>=1.4.1 (from cryptography->ansible) Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl Saved ./six-1.15.0-py2.py3-none-any.whl Collecting cffi!=1.11.3,>=1.8 (from cryptography->ansible) Downloading https://files.pythonhosted.org/packages/d1/fd/10e2050b3afcb03d78b2b33212c3ff17b3985ae25d0feb34c0c9eb417549/cffi-1.14.1-cp37-cp37m-manylinux1_x86_64.whl (401kB) 100% |████████████████████████████████| 409kB 1.1MB/s Saved ./cffi-1.14.1-cp37-cp37m-manylinux1_x86_64.whl Collecting MarkupSafe>=0.23 (from jinja2->ansible) Using cached https://files.pythonhosted.org/packages/98/7b/ff284bd8c80654e471b769062a9b43cc5d03e7a615048d96f4619df8d420/MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl Saved ./MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography->ansible) Using cached https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf82342dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl Saved ./pycparser-2.20-py2.py3-none-any.whl Successfully downloaded ansible PyYAML cryptography jinja2 six cffi MarkupSafe pycparser
---------------------------------------- Failed building wheel for ansible Running setup.py clean for ansible Running setup.py bdist_wheel for pycparser ... error Complete output from command /home/kevin/myGreatProject/myVirtualEnvironment/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-bz2ssx4w/pycparser/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-0z6zygi4 --python-tag cp37: error: invalid command 'bdist_wheel' ----------------------------------------
Collecting ansible==
Could not find a version that satisfies the requirement ansible== (from versions: 1.0, 1.1, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.9.0.1, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6, 2.0.0.0, 2.0.0.1, 2.0.0.2, 2.0.1.0, 2.0.2.0, 2.1.0.0, 2.1.1.0, 2.1.2.0, 2.1.3.0, 2.1.4.0, 2.1.5.0, 2.1.6.0, 2.2.0.0, 2.2.1.0, 2.2.2.0, 2.2.3.0, 2.3.0.0, 2.3.1.0, 2.3.2.0, 2.3.3.0, 2.4.0.0, 2.4.1.0, 2.4.2.0, 2.4.3.0, 2.4.4.0, 2.4.5.0, 2.4.6.0, 2.5.0a1, 2.5.0b1, 2.5.0b2, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3, 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6, 2.5.7, 2.5.8, 2.5.9, 2.5.10, 2.5.11, 2.5.12, 2.5.13, 2.5.14, 2.5.15, 2.6.0a1, 2.6.0a2, 2.6.0rc1, 2.6.0rc2, 2.6.0rc3, 2.6.0rc4, 2.6.0rc5, 2.6.0, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.6.6, 2.6.7, 2.6.8, 2.6.9, 2.6.10, 2.6.11, 2.6.12, 2.6.13, 2.6.14, 2.6.15, 2.6.16, 2.6.17, 2.6.18, 2.6.19, 2.7.0.dev0, 2.7.0a1, 2.7.0b1, 2.7.0rc1, 2.7.0rc2, 2.7.0rc3, 2.7.0rc4, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.7.5, 2.7.6, 2.7.7, 2.7.8, 2.7.9, 2.7.10, 2.7.11, 2.7.12, 2.7.13, 2.8.0a1, 2.8.0b1, 2.8.0rc1, 2.8.0rc2, 2.8.0rc3, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.8.5, 2.9.0b1, 2.9.0rc1, 2.9.0rc2, 2.9.0rc3)
No matching distribution found for ansible==
Improved version :
),
' '\n
' | grep -E '^[0-9]
' | sort -nr | less2.9.0rc3 2.9.0rc2 2.9.0rc1 2.9.0b1 2.8.5 2.8.4 2.8.3
building 'psutil._psutil_linux' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/psutil x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=563 -DPSUTIL_LINUX=1 -I/home/bob/virtualenvs/projectName/include -I/usr/include/python3.7m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.7/psutil/_psutil_common.o psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory the line above the error #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 the error
Sometimes it's the line above this error you should look at. It should tell you what package is missing.
Check :
libpython3.7-dev:amd64: /usr/include/python3.7m/Python.h
virtualenv is the Python 2 tool to interact with virtual environments and won't be discussed here. I'll focus on Python 3 tools and methods only.
The Python 3 tool to manage virtual environments is venv, which —depending on your distro / version :
(myVirtualEnvironmentName)
showing the virtual environment is enabled.
Traceback (most recent call last): File "/usr/local/bin/youtube-dl", line 6, in <module> from youtube_dl import main ImportError: cannot import name 'main'
/usr/bin/mandb: can't search directory /usr/local/man: Permission deniedwhich is pretty unexpected since this was run as root. Looks like permissions were pretty f*cked up already :
lrwxrwxrwx 1 root staff 9 Oct 11 2016 /usr/local/man -> share/man
drwx--S--- 3 root staff 4096 Mar 19 11:14 /usr/local/share/man
Solution :
This GitHub issue details the reasons of this error (the PEBKAC part, notably) and hints to debug / fix.
/usr/local/bin/youtube-dl
Traceback (most recent call last): File "/usr/local/bin/youtube-dl", line 6, in <module> from youtube_dl import main ImportError: cannot import name 'main'
#!/usr/bin/python3
(returns the 'usage' page, but no error)
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 639, in __init__ File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 695, in add_entry File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2012, in find_on_path PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/youtube_dl-2019.3.18.dist-info'
drwx--S--- 6 root staff 4.0K Mar 19 08:52 youtube_dl drwx--S--- 2 root staff 4.0K Mar 19 08:52 youtube_dl-2019.3.18.dist-info
(the 'usage' page )
This is highly context-specific and not exactly a "clean" solution, but maybe this will give you hints to find the root cause on your side... If anything, this issue,at least, led me to some best practices :
First, some general advice. It is assumed that anyone encountering issues will have failed to follow some part of this advice. Listing these items here is not intended to imply that "it's your fault and we won't help", but rather to help users to identify what went wrong, so that they can work out what to do next more easily.
PATH
issues you need to be aware of here. We'll cover these later. Put simply, it's possible to follow this advice, and still hit problems, because you're not actually running the wrapper you installed as --user....
MANY lines describing the exceptions
...
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
Collecting pip Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB) 100% |████████████████████████████████| 1.3MB 781kB/s Installing collected packages: pip Successfully installed pip-9.0.1
Collecting pip Using cached pip-9.0.1-py2.py3-none-any.whl Collecting wheel Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB) 100% |████████████████████████████████| 51kB 718kB/s Installing collected packages: pip, wheel Successfully installed pip-9.0.1 wheel-0.30.0
Collecting mps-youtube Downloading mps_youtube-0.2.7.1-py3-none-any.whl (74kB) 100% |████████████████████████████████| 81kB 974kB/s Requirement already satisfied: pafy!=0.4.0,!=0.4.1,!=0.4.2,>=0.3.82 in /usr/lib/python3/dist-packages (from mps-youtube) Installing collected packages: mps-youtube Successfully installed mps-youtube-0.2.7.1
#!/usr/bin/env python3 class Person(object): def __init__(self, firstName, lastName, age): self.firstName = firstName self.lastName = lastName self.age = age def getItem(self, itemName): return getattr(self, itemName) user = Person('John', 'Smith', 42) for item in [ 'firstName', 'lastName', 'age' ]: print(user.getItem(item))will display :
John Smith 42
some python code
is code stored in a fileimport math print(math.pow(2,38))
274877906944.0
Next level : http://www.pythonchallenge.com/pc/def/274877906944.html
inTable = 'KOE' outTable = 'MQG' message = 'KOE' print(message.translate({ord(x): y for (x, y) in zip(inTable, outTable)}))
MQG
List comprehensions provide a more concise way to create lists in situations where nested loops would currently be used.
print({x: y for (x, y) in zip(inTable, outTable)})
{'K': 'M', 'E': 'G', 'O': 'Q'}
print({ord(x): y for (x, y) in zip(inTable, outTable)})
{75: 'M', 69: 'G', 79: 'Q'}
inTable = 'abcdefghijklmnopqrstuvwxyz' outTable = 'cdefghijklmnopqrstuvwxyzab' message = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj." print(message.translate({ord(x): y for (x, y) in zip(inTable, outTable)}))
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.A smarter solution to build the
inTable
and outTable
strings :
import string inTable = string.ascii_lowercase outTable = string.ascii_lowercase[2:] + string.ascii_lowercase[:2]
Next level : http://www.pythonchallenge.com/pc/def/ocr.html
The question is in the HTML source :
find rare characters in the mess below: %%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{* @##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{$!@#$%)!@(& +^!{%_$&@^!}$_${)$_#)!({@!)(^}!*^&!$%_&&}&_#&@{)]{+)%*{&*%*&@%$+]!*__(#!*){%&@++ !_)^$&&%#+)}!@!)&^}**#!_$([$!$}#*^}$+&#[{*{}{((#$]{[$[$$()_#}!@}^@_& ...
localFile='./level02.txt'; >"$localFile"; wget -O "$localFile" http://www.pythonchallenge.com/pc/def/ocr.html; sed -i '38,1257 !d' "$localFile"; sed -ri 'sa[][)({}@%&$_+*^#!]aag' "$localFile"; sed -i '/^$/ d' "$localFile"; tr '\n' '\0' < "$localFile"
Next level :
#!/usr/bin/env python3 import lxml.etree as ET dom = ET.parse('data.xml') xslt = ET.parse('stylesheet.xsl') transform = ET.XSLT(xslt) newdom = transform(dom) print(ET.tostring(newdom, pretty_print=True))Due to Python's byte objects, print's internal logic and things that are not yet clear to me (and Python3.x limitations on lxml side ?), this script outputs a "byte object string", that I'll clean (the ugliest possible way) with sed :
import datetime from datetime import datetime, timedelta timeFormat = '%Y-%m-%d %H:%M:%S' now = datetime.now() print(now.strftime(timeFormat)) future = now + timedelta(seconds=500) print(future.strftime(timeFormat))
apt install python3-pip; pip3 install requests