Python 3.7 ModuleNotFound - python

I'm using MSYS2 but without pip (SSL error), and when I try to run
python vin.py
It throws me this error:
Traceback (most recent call last):
File "vin.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
What can I do? Thanks in advance

I think it is because you installed the requests module for Python 3 while you are running Python 2.
To specifically install the package for Python 2, try entering this command:
pip2 install requests
or
python -m pip install requests
If you want to run the script with Python 3 instead, simply change python to python3, so:
python3 vin.py

It is better to use a virtualenv:
First create a virtualenv for your project and activate it:
python -m venv my_project
source my_project/bin/activate
Then install Requests:
pip install requests
To test: run python and import requests
>>> import requests

Related

Pytorch is installed but is not working on ubuntu 18.04

I am trying to install Pytorch via pip on ubuntu 18.04.I have python 3.6 and my laptop is HP-Pavilion notebook 15
The installation seems to be right because i get the message:
Installing collected packages: torch, torchvision Successfully
installed torch-1.3.1+cpu torchvision-0.4.2+cpu
i run the verification code and it is ok
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
However, when i close the terminal or reboot and try to run he same code i get the error:
Traceback (most recent call last):
File "torch.py", line 2, in
import torch
AttributeError: module 'torch' has no attribute 'rand'
How are you executing the python script? Which python are you using? Maybe you installed the package in a different python version?
Try to set alias to the python you want to use:
alias python=/usr/local/bin/python3.6
Then pip install the package with that python alias you will always be using.
python pip install <package name>
Python now will install the package in the python files with the alias python - heading to files: /usr/local/bin/python3.6
Let me know if the error still occurs!
Install pytorch using pip through the below command:
pip3 install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
for any reference go through the official website of pytorch.
Change your file .py to another name, you named torch.py when you import torch it will call ur torch.py

ModuleNotFoundError: No module named 'ruamel'

I'm using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36, the ruamel YML library is imported using the code from ruamel.yaml import YAML. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3), if I run pip list, I can clearly see the most up to date version of ruamel.yaml:
If I run pip show ruamel.yaml, I get the following output:
I'm running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don't understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml project page, it looks like the script is calling the library as it should be.
Thanks in advance
In my case, I was installing this with pip3 install ruamel.yaml, and it was puting the package in /usr/local/lib/python3.9/site-packages/, but the python3 binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
pip is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml.
you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[#]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml

ModuleNotFoundError: No module named 'requests' after pip install [duplicate]

This question already has answers here:
ModuleNotFoundError: No module named 'requests' but it's installed?
(2 answers)
Closed 1 year ago.
I know similar questions have been asked before but I couldn't find the solution to my problem.
I am getting the following error message after trying to import requests:
C:\Users\Jm\PycharmProjects\Test\venv\Scripts\python.exe C:/Users/Jm/PycharmProjects/Test/Test_001
Traceback (most recent call last):
File "C:/Users/Jm/PycharmProjects/Test/Test_001", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
I only have one version of python installed and python -m pip install requests is saying all the requirements are already satisfied.
Run this code:
C:\Users\Jm\PycharmProjects\Test\venv\Scripts\python.exe -m pip install requests
This forces the installation directory to your python install.
This gives a much different effect than simply python -m pip install requests
As #Daniel Scott mentioned before use the command mentioned above or below
$: path-to-your-python-command -m pip install name-of-module
If you are using linux/mac then you can find path-to-your-python command using:
$: which python3
/usr/bin/python3
Lets say your python is installed here /usr/bin/python3 and the module you are installing is requests. Then you can use:
$: /usr/bin/python3 -m pip install requests

ModuleNotFoundError after installing requests package

I am on Mac OS Sierra, with home-brew, pip and python3 installed. I Tried running a script that required the requests module, but I keep getting this error:
Traceback (most recent call last):
File "listing_seq.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Despite running:
sudo pip3 install requests
sudo pip install requests
sudo pip install requests --upgrade
Any suggestions?
Update:
When I try running using virtualenv I get:
Running virtualenv with interpreter /usr/local/bin/python3
ERROR: File already exists and is not a directory.
Please provide a different path or delete the file.
The most common error is having another file with the name of any of the libraries you requested in the same path.
The other possible error is if the python you are using to execute the file is not python 3 but rather the defalut python from your OSX. See the accepted answer on this for better understanding of a possible issue. Also share your code to identify the bug.

How to install whois python module in windows

I want to install whois python module in windows.
i tried to install whois module using command
python setup.py install
downlaoded from
https://pypi.python.org/pypi/pythonwhois
but when i try to import whois module it gives error
>>> import whois
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import whois
ImportError: No module named whois
thanx in advance
I would suggest that you should install pip first.
http://docs.python-guide.org/en/latest/starting/install/win/
OR
How do I install pip on Windows?
After that go to command prompt and simply type:
pip install whois
This should do it.
Update: Alternate way to install whois?
Step 1: After installing pyhton, add the following to the PATH in the Environmental Variables.
C:\Python27\;C:\Python27\Scripts\
Step 2: Download ez_setup.py. Run it and it will install Setuptools.
Step 3: Go to command line/powershell and type:
easy_install whois
Step 4: You are done! Go to python and import whois
try using pip - http://pip.readthedocs.org/en/latest/installing.html, download the file, run the script and then you can do like this - http://www.pythonforbeginners.com/dns/using-pywhois, pip install python-whois.

Categories