Error while importing requests and pyvmomi module in python - python

I tried to import requests in my python scripts but it shows error
>>>import requests
ImportError: No module named requests
So I tried to install it using easy_install
Path\easy_install.exe requests
in Windows, but it shows no response and when I run import again, it shows the same error.

Make sure you have requests and pyvmomi directories located under c:\pythonXXX\Lib\site-packages.
In case of absence, try to install those packages via pip on windows(here you have the instructions to install pip on windows).
Once you have done installation of pip, open the CMD prompt with administrative privilege and use the following commands to install the required python packages :
pip install requests pyvmomi
Now you could see that the packages are successfully installed.
After this, open the "System Properties" window and select "Advanced" tab and click the button "Environment variables" to set required path variables as shown below :
PYTHONHOME - "c:\Python278"
PYTHONPATH - "c:\Python278\Lib"
Edit the system variable Path and append the following :
%PYTHONHOME%;%PYTHONPATH%;
Finally open idle or python shell and import the packages as follows :
import requests
import pyVmomi
Now you are able to import with out any problem. Whenever you import packages, also check the spelling and case sensitive of the name.

Open cmd.exe that run this command:
pip install requests
Another solution is to install Anaconda which is Python distribution that comes with great package manager from here: Anaconda
Anconda python comes with built in requests library (and many more useful libraries)

Related

Having issue importing requests and I assume it's my python runtime not being set correctly

Probably stupidly I tried to install the latest version of Python, in this case using the download from python site, but after doing that I was then getting python still running on the previous version python-3.6. I'm on OSX and was using sublime.
So I have been trying to work out how to update it to use the newest version. I've followed; https://opensource.com/article/19/5/python-3-default-mac.
All of the responses to queries now point to the python-3.9.5 version. So that's great and my runtime is using that. However after installing the requests using pip install I get the following error when running.
import requests
ModuleNotFoundError: No module named 'requests'''
[path: /Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
I stumbled upon Modules are installed using pip on OSX but not found when importing which I have been trying to work through.
I have been able to run the import command successfully in terminal, however it's intermittent as I've tried again and it's broken, so I'm lost. I'm running it something trying to run the python3.6 version, which after updating I followed these instructions to remove when I have uninstalled that from my mac https://www.macupdate.com/app/mac/5880/python/uninstall.
If there is any ideas, would love some help, mainly to try and tell me what that error message is telling me.
In particular, what does this mean?
[path: /Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.6/
I should clarify too; when I run 'pip list'
I see
requests 2.25.1
Assuming that you are not installing requests package properly, and assuming your python executable is named python:
python -m pip install requests
If however, your python executable is named something else instead, e.g. python3, replace python with that name:
python3 -m pip install requests

ModuleNotFoundError: No module named 'requests' but it's installed?

I used the command pip install requests in CMD and successfully installed the requests module, but when I try and import it to my file in PyCharm it throws
"ModuleNotFoundError: No module named 'requests'
I saw a couple other posts about this issue but did not find a working solution.
As a side note I have successfully run this code in my Python IDLE so I presume this is not a code issue, and just an issue with my PyCharm settings.
Traceback (most recent call last):
File "C:/Users/danie/PycharmProjects/Web_Scraping_Project/Web_Scraper.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Process finished with exit code 1
You have to activate the virtual environment.
source venv/bin/activate
pip install requests
Or you can add the library, from the PyCharm GUI.
There is a "+" on the edit interpreter in settings in the, click on it and search for the requests library.
Seems as if your project is using a virtualenv python environment. The pip install you did is probably on your system wide python installation.
You can install packages by activating your virutalenv (source path/to/venv/bin/activate) and using pip as usual, installing packages using the PyCharm interface (you can see a litte "+" button in your screenshot) or just by using the terminal in PyCharm (this should activate the virtualenv automatically).

ModuleNotFoundError: No module named 'websocket' even though I installed pip install websocket

I am trying to run some code that has 'import websocket' however I am getting the error: ModuleNotFoundError: No module named 'websocket'
I have Python 3.7.3 and I am running in Spyder (if that makes a difference).
So from other questions/answers I found on here, in my cmd I ran pip install websocket and then also pip install websocket-client when the first one didn't run.
I am still getting the ModuleNotFoundError. Does it matter the location/folder of the code or where I install the pip command in cmd?
My python code starts with these import statements:
import json
import websocket
import traceback
import helper
import ssl
import time as time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
In cmd I ran:
C:\Users\myname>pip install websocket
and also:
C:\Users\myname>pip install websocket-client
The error I am getting is:
File "C:/Users/micki/Downloads/Derbit-Volatility-Visulization-master/Derbit-Volatility-Visulization-master/Volatility Surface Class.py", line 2, in <module>
import websocket
ModuleNotFoundError: No module named 'websocket'
Not sure, as you did not cover how you installed and are using Spyder, though I think it is probably an issue with your environment. You might also find that you are missing the module "helper" as well. There's two easy options as follows:
If you installed and are using Spyder via conda or anaconda, follow their documentation on installing websocket-client to the correct environment found here.
The second option (the preferred option IMHO, as you can use any IDE or text editor going forward), regardless of how you installed Spyder, would be to create a python virtual environment python3 -m venv /path/to/new/virtual/environment, pip install all your dependencies in said environment, then link Spyder's interpreter to the interpereter that was installed when you made the environment. In Spyder, go to Tools -> Preferences -> Python interpreter -> check the "Use the following Python interpreter:" radio button and enter the path to the interpreter from the environment you just created. For reference, see docs on making and using a python venv here.
If the websocket and websocket-client doesn't work, try:
pip install websocket_client
This solved my issue:
sudo pip install websocket-client

Python: ModuleNotFound Error

I downloaded multiple modules (Discord API, cx_Freeze) (pip download, Windows 10) and now I wanted to use them.
But when I want to import them, it says there isn’t any module.
From my former Python using (before resetting computer) I‘ve added a pycache folder and it worked for one module. I‘m not able to reproduce it for other modules. What to do?
I‘ve only one Python version (3.6.5) on PC.
I‘ve checked the \site-packages folder and they‘re there.
If you are using python3 then try downloading the library using
pip3 install libname
but if you are using python2 then install the library using
pip2 install libname or just pip install libname
try with these command and reply
try installing your library using the command prompt in normal user and with the admin user so that you will get to know that what is happening and also if it is still not working then try installing the library into the same folder of your project using pip custom install command
pip install -t <direct directory> <package>
then use the import statement
For Example I used
pip2 install -t c:\Users\Nav\Desktop\projectss cx_freeze
then i imported the library using
#from cx_Freeze import setup, Executable
import cx_Freeze
from cx_Freeze import *
it worked.
Previously i was getting error like :
File "C:\Python27\lib\site-packages\cx_Freeze\__init__.py", line 10, in <module>
from cx_Freeze.finder import *
ImportError: No module named finder
After custom install it is working

ImportError: No module named bs4 on mac

I sat down tonight and have decided to leran how to use python. Inspired by this webpage scraping article.
cam.ly/danesblog/2011/01/craigslist-arbitrage/
after working through a tutorial I:
1) downloaded and installed python: http://www.python.org/getit/ first 3.3 then 2.7
2) downloaded bs4: www.crummy.com/software/BeautifulSoup/bs4/download/
3) followed Brian Clapper's instructions:
How can I install the Beautiful Soup module on the Mac?
tried both easy_install and python setup.py install methods
I am still getting "ImportError: No module named bs4"
Python is installed in applications folder, the bs4 package auto installs in Library
Is this the problem? I tried copying and moving the folder into Python application, but didn't work.
I have also tried both forms:
from BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
Thank you for the support.
The solution is in setting up the PATH the packages get installed. EPD or Canopy create their VirtualEnv set up in the .\~profile and .\~bash_profile files. These path may not be identical to the path pip install or easy_install try to install the packages. If you open bash_profile or profile files there should be a path similar to this :
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/test_user/Library/Enthought/Canopy_64bit/User/bin/activate
I am using Enthought as my python editor so yours will be something else but what is important is if you are using pip or easy_install the address the python packages are installed should point here. Or put another way, your active virtual environment set up is in this address.

Categories