I am currently trying to run a sample code I code off of the internet.
While trying to run it using python2.7, I get the following ERROR :
# python2.7 example.py
Traceback (most recent call last):
File "example.py", line 9, in <module>
from http.server import HTTPServer
ImportError: No module named http.server
I tried to run the following :
# pip install http.server
Collecting http.server
Could not find a version that satisfies the requirement http.server (from versions: )
No matching distribution found for http.server
But when I use python3, it does not give me the ERROR. Rather gives the ERROR :
# python3 example.py
Traceback (most recent call last):
File "example.py", line 13, in <module>
from prometheus.client import Gauge
ImportError: No module named 'prometheus.client'
Im trying to install prometheus.client using pip and pip3 but nothing.
# pip install prometheus.collectors
Collecting prometheus.collectors
Could not find a version that satisfies the requirement prometheus.collectors (from versions: )
No matching distribution found for prometheus.collectors
# pip3 install prometheus.collectors
Collecting prometheus.collectors
Could not find a version that satisfies the requirement prometheus.collectors (from versions: )
No matching distribution found for prometheus.collectors
How can I get the missing libraries ?
EDIT ::
In the below example I am using a very minimalist approach (again from github)
from prometheus_client import start_http_server, Summary
import random
import time
# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
# Decorate function with metric.
#REQUEST_TIME.time()
def process_request(t):
"""A dummy function that takes some time."""
time.sleep(t)
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
# Generate some requests.
while True:
process_request(random.random())
Running the above code yields :
# python3.4 main.yaml
Traceback (most recent call last):
File "main.yaml", line 1, in <module>
from prometheus_client import start_http_server, Summary
ImportError: No module named 'prometheus_client'
Whereas I do have the library installed.
# pip3 install prometheus_client
Requirement already satisfied: prometheus_client in /usr/lib/python2.7/site-packages
I'm running on ubuntu 18.10 and i got the same issue, and i have python2 install already. I was able to solved it by installing python3 and python3-pip like below.
sudo apt install python3
sudo apt install python3-pip
pip3 install prometheus_client
May be helpful to somebody!
http.server is a module in Python 3.
See the note for SimpleHTTPServer in Python 2:
Note The SimpleHTTPServer module has been merged into http.server in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.
For prometheus.client, you want pip install prometheus_client. See https://github.com/prometheus/client_python
README.md from the repository you linked states:
Deprecated, use: https://github.com/prometheus/client_python
I faced the exact same problem. I installed pip3 using python3 -m pip install --upgrade pip. After that ran pip3 install prometheus_client. After this, the issue got fixed.
sudo -H pip3 install prometheus_client
just worked for me
Found here
https://github.com/b-harvest/terra_oracle_voter_deprecated/issues/17
Related
I wanted to run a script that would scan my network and that script uses a awesome library called who-is-on-my-wifi. I have installed the module to run the script but i get errors from the prompt saying that it cannot detect such a module in the system.
This is the script.
from who_is_on_my_wifi import *
WHO = who()
for i in range(0, len(WHO)):
print(WHO[i])
And this is the error that i get.
python scanner.py
Traceback (most recent call last):
File "scanner.py", line 1, in <module>
from who_is_on_my_wifi import *
ImportError: No module named who_is_on_my_wifi
This is the proof that i have installed the module
pip3 install 'who_is_on_my_wifi'
Requirement already satisfied: who_is_on_my_wifi in /home/harein/.local/lib/python3.8/site-packages (1.2.0)
Requirement already satisfied: getmac in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.8.2)
Requirement already satisfied: python-nmap in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.6.1)
Any suggestions on how i can avoid this can continue executing my script ?
EDIT
The script finally executed the way i want by changing the,
python scanner.py to python3 scanner.py
You guys were right, it was the way how i executed the script that generated this error and it was not a problem in the module apparently.
I would like to thank everyone who gave the support.<3
When trying to
import this_is_not_a_module
the error you get:
ImportError: No module named this_is_not_a_module
is the error raised by Python 2.
Python 3 would raise a different one:
ModuleNotFoundError: No module named 'this_is_not_a_module'
So, your actual problem is that your system tries to execute your script with some Python 2 version, while you installed your module for your Python 3.8 version.
sometimes you can't import modules because you have installed two python versions(or conda along with it). if you have, delete one of your python versions or activate conda and try importing your module, or just try:
pip uninstall who_is_on_my_wifi
pip install who_is_on_my_wifi
I usually tend to install modules per project and use virtualenv for it.
It kind of links respective versions of programs (like python interpreter, pip and so on) and takes care of PYTHONPATH and the way of installed dependencies.
$ pip3 install virtualenv
$ virtualenv whoisonwifi
$ source whoisonwifi/bin/activate
$ pip --version
pip 21.0.1 from
/mnt/devel/workonhome/whoisonwifi/lib/python3.7/site-packages/pip
(python 3.7)
$ pip install 'who_is_on_my_wifi'
from there your code (sort of) works for me.
I'm using a python code using the package tqdm, I installed it with pip
androiddl#androiddl:~$ pip install tqdm Collecting tqdm Using cached
https://files.pythonhosted.org/packages/76/4c/103a4d3415dafc1ddfe6a6624333971756e2d3dd8c6dc0f520152855f040/tqdm-4.30.0-py2.py3-none-any.whl
Installing collected packages: tqdm Successfully installed tqdm-4.30.0
After this success message when I'm trying to run my python script I have this error :
androiddl#androiddl:~/...$
python3 download.py "com.facebook.katana" Traceback (most recent call
last): File "download.py", line 10, in
from playstore.playstore import Playstore File "/home/.../playstore/playstore.py",
line 12, in
from tqdm import tqdm ModuleNotFoundError: No module named 'tqdm'
How can I fix it ? Thank you
It seems like pip is hooked up to Python 2, and not python3, which is what you are using to run your script. Try using pip3 instead. If that doesn't work, a quick way to solve it is to use python3 -m pip install ... for now, although it's nice to have that command located at pip3. Try looking at an answer like How to install pip with Python 3? for that.
homebrew has again broken python for about third time. Im now having issues getting dependencies to work again. At this point I am unable to install yaml.
Collecting yaml
Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml
Some other suggestions have said to try pyaml, which again simply tries to import yaml and fails
Traceback (most recent call last):
File "script.py", line 13, in <module>
import pyaml
File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module>
import os, sys, io, yaml
ImportError: No module named yaml
Anyone have an idea how to get this sorted out?
There are two packages with somewhat unfortunate naming in the Python Package Index.
pip install pyyaml lets you import yaml. This package enables Python to parse YAML files.
pip install pyaml lets you import pyaml. This package allows pretty-printing of YAML files from Python, among other things. It requires pyyaml to be installed.
So the way forward for you is:
Install pyyaml, preferably using pip
Install pyaml
Profit
Step 0 would be to run everything from a virtual environment to prevent homebrew from messing with your Python ever again. This option also lets you run multiple versions of Python, not just the one required by homebrew.
The solution for me turned out to be homebrew changing python to python2, which I believe precludes using the brew version instead of the system version
eg python script.py >> python2 script.py
Additionally, linking the system version of python to the brew python2 version helped as well:
cd /usr/local/bin && ln -s ../Cellar/python/2.7.13_1/bin/python2 python
I'm also hesitant the accepted answer will work, as pyaml is still attempting to import yaml, via __init__.py; which does not exist even after installing both packages
$ pip install pyaml
Collecting pyaml
Using cached pyaml-17.7.2-py2.py3-none-any.whl
Requirement already satisfied: PyYAML in ~/Library/Python/2.7/lib/python/site-packages (from pyaml)
Installing collected packages: pyaml
Successfully installed pyaml-17.7.2
$ pip install yaml
Collecting yaml
Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml
eg
File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module>
import os, sys, io, yaml
I tried to install PyRTF from PyPi but this doesn't work.
The package itself can be found:
$ pip3 search PyRTF
PyRTF (0.45) - PyRTF - Rich Text Format Document Generation
But installing it fails:
$ sudo -H pip3 install PyRTF
Collecting PyRTF
Could not find a version that satisfies the requirement PyRTF (from versions: )
No matching distribution found for PyRTF
I am confused.
There is a Python 3 version of PyRTF called PyRTF3. You can find it Here.
PS - Use pip install PyRTF3 or pip install rtfw for Python 2, pip install PyRTF doesn't work.
You could use the raw url from the sourceforge page in order to get it:
pip install https://sourceforge.net/projects/pyrtf/files/pyrtf/0.45/PyRTF-0.45.tar.gz/download
But, to be honest, I don't think this library is maintained on the project website the last update was from 2005, 11 years ago.. Additionally, it uses a line of the form:
from types import StringType
which only exists in Python 2.x not 3.x. Importing it raises that specific error too:
>>> import PyRTF
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jim/anaconda3/lib/python3.5/site-packages/PyRTF/__init__.py", line 1, in <module>
from PropertySets import *
File "/home/jim/anaconda3/lib/python3.5/site-packages/PyRTF/PropertySets.py", line 12, in <module>
from types import StringType
ImportError: cannot import name 'StringType'
So maybe it was designed for Python 2.x? I can't remember when StringType was removed from the 3.x series, maybe it targeted an old version of it.
I'm trying to get up and running with an ipython plugin for gedit3, but it requires ipython-listener, and when I try to launch it I get this:
Traceback (most recent call last):
File "/usr/local/bin/ipython-listener", line 27, in <module>
from IPython.frontend.terminal.embed import InteractiveShellEmbed
ImportError: No module named terminal.embed
I'm running ipython version 0.10.2 and python version 2.7.2+
I tried to do pip install terminal.embed but couldn't find it:
Downloading/unpacking terminal.embed
Could not find any downloads that satisfy the requirement terminal.embed
No distributions at all found for terminal.embed
Storing complete log in /home/amanda/.pip/pip.log
So now what?
I tried to do pip install terminal.embed but couldn't find it
It's not a package, it's part of IPython. Your IPython is just too old (by a couple of years).
That plugin depends on IPython ≥ 0.11 (current is 0.13.1). Try:
pip install --upgrade ipython