I have never used Python before and am trying learn it on the fly. I have this file. I installed python 2.7 have added it the path. when I try python [filename].py I get errors saying
import requests,sys,csv,os,re,urllib2,urllib,time,traceback,string
ImportError: No module named requests.
Am I missing something here. Where would I find these and how do I get this running
You need to install the requests package:
pip install requests
Tutorial about installing packages here
Related
I'm trying to install a few packages (beautifulsoup4 and requests) for a project.
I installed these packages by running these commands in the terminal on macOS:
pip3 install beautifulsoup4
pip3 install requests
both did install successfully.
Now if I open my project in PyCharm, I can import the modules by using:
from bs4 import BeautifulSoup
import requests
Both packages are imported successfully and can be used in my code.
To be sure everything was installed correctly, I looked at the venv/lib/Python3.10 folder. beautifulsoup4-4.10.0.dist-info, bs4, requests and requests-2.27.1.dist-info are present.
However, when I run the CGI script (Python), I get the following error in the terminal:
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Even when I open a new terminal window and run the following commands:
python3
>>> from bs4 import BeautifulSoup
it runs fine without any errors.
The same issue happens for the requests package.
I also ran pip3 install bs4 but that also didn't fix anything.
I found what caused the issue. bs4 and requests were both installed correctly but in my CGI script, I used the wrong Python path. I had to change #!/usr/bin/python3 to the path that which python3 gave me.
I would recommend to always install packages using python3 -m pip install <name_of_the_package>. In this way you can be sure that you are using the correct pip.
To make sure that the python you a using really has the packages installed, try python3 -m pip list.
If all is good, check if the python interpreter the pycharm is using in your project is the right one.
It sounds to me that in pycharm you're using a virtual environment, but when you are using python3 at the terminal, you a using the main installation.
I'm extremely new to Python, so I can only apologize for my unadulterated incompetence.
I'm trying to learn to web scrape, so I did pip install requests and that worked fine.
In PyCharm, however, I receive ModuleNotFoundError: No module named 'requests' when I try import requests.
PyCharm offers from pip._vendor import requests to rectify this, but from this I get:
AttributeError: partially initialized module 'pip._vendor.requests' has no attribute 'Session' (most likely due to a circular import)
Any help would be greatly appreciated.
PyCharm may be using a different python (perhaps from a virtualenv) than the one you pip installed from.
You should also be able to pip install requests from PyCharm's terminal, which should be using the same python as the code you ran.
If you're not using a virtual environment, or similar, I'd highly recommend it. https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html# might be useful for you.
Try this: python -m pip install requests or this python3 -m pip install requests
I'm very much new to Python and right now I'm trying to use Python for one of my automation tasks.
I'm trying to execute Execute.py while doing so I learned that my python setup should have modules requests (so downloaded 2.21.0),urllib3 (so downloaded 1.21.1), chardet(so downloaded 3.0.4).
My Python version is 3.7.3
When I execute my execute.py I get the following error:
File "C:\Users\ABC\Downloads\python-3.7.3-embed-amd64\requests\__init__.py", line 87, in <module>
check_compatibility(urllib3.__version__, chardet.__version__)
AttributeError: module 'urllib3' has no attribute '__version__'
So just like we have in chardet folder, I have created a version.py under urllib3 folder.
But still, I'm getting the same error.
Please, can someone help me with this? Which is taking my lot of time to find the resolution.
You can uninstall and then install again all required package, by pip uninstall and pip install .
you can also upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used (command require for this).
pip install --upgrade
You should use pip to install your libs, it will take care of the dependencies. It seems your urllib3 is not up to date...
Open a command prompt, and run:
pip install requests --upgrade
My answer is about probably where i might have gone wrong.(Nothing wrong in above two answers)
I had installed executable Python,in which i dint have PIP (though its 3.7 version)
so i was struggling to install PIP and all other modules(since im am new)
So ---I had used Web based installation (https://www.python.org/downloads/release/python-373/)
which had PIP and set the Python PATH on the go using which i upgraded required modules like others answered here.
Which has come handy to do the rest of the job ,where i dint come across any issues while executing.
Thanks
I had the same problem with the requests. It was for A circular dependency occurs when two or more modules depend on each other. This is for the fact that each module is defined in terms of the other.
Please try to rename your file. The error for this error is usually due to a conflict with the file name where you are trying to import the requests module.
I was also having same problem, where my file name was token.py and I was trying to import the requests module. I changed the file name and it worked.
I'm trying to install web.py, and I did the next steps:
Download web.py-0.3.7, and extract it on c://web.py-0.3.7
Run the next command:C:\>python C:\web.py-0.37\setup.py install
and it gives me the next error: import utils, db, net, wsgi, http, webapi, httpserver, debugerror ImportError: No module named 'utils'
How can I install and use web.py?
The issue is web.py is native for python 2.7+, however, there are several options.
Install python 2.7+ (recommend using virtualenv)
Check out this group that is porting web.py to python 3.x
Use bottle.py as an alternative (Native to 2.5+ and 3.x)
Aside from these options to directly address the issue of 'utils' not being found, you can download the package here. This does not get around the compatibility issues but just for reference.
I had this same Error using pip install. I just ran pip2 install web.py and it successfully installed. (for anyone still reading this in 2016)
web/__init__.py relies on relative path. Try this:
pip install web.py==0.40.dev0
A website had this solution
I am a newbie (just 1 week) to this Python world. I tried installing django-mssql, but when I tried to import the library (using import sqlserver_ado.dbapi), I got this error message:
ImportError: No module named pythoncom
I tried to look for that library without success.
Can you guys point me in the right direction?
You are missing the pythoncom package. It comes with ActivePython but you can get it separately on GitHub (previously on SourceForge) as part of pywin32.
You can also simply use:
pip install pywin32
If you're on windows you probably want the pywin32 library, which includes pythoncom and a whole lot of other stuff that is pretty standard.
You should be using pip to install packages, since it gives you uninstall capabilities.
Also, look into virtualenv. It works well with pip and gives you a sandbox so you can explore new stuff without accidentally hosing your system-wide install.
$ pip3 install pypiwin32
Sometimes using pip3 also works if just pip by itself is not working.
Just go to cmd and install pip install pywin32 pythoncom is part of pywin32 for API window extension....