My python version is: Python 2.7
I did an easy_install mechanize then I tried running a script and I'm getting this:
File "test.py", line 2, in <module>
import mechanize
ImportError: No module named mechanize
If you need any other information let me know.
Try this in case pip or easy_install, for whatever reason, aren't working:
Download the source code from http://pypi.python.org/packages/source/m/mechanize/mechanize-0.2.5.tar.gz
Unzip the package, go to the command line, change into the folder that was extracted and type:
python setup.py install
If you're on Linux/Mac, you may need to type the following:
sudo python setup.py install
Would like to add something for some future users:
In case some of the users get the error "No module named '_version'"
Mechanize however doesn't support Python 3 so you should install a Python 2.x release (the latest available is 2.7.3), install the mechanize package there and then retry running your script.
Related
As the title says, apparently VsCode doesn't recognize several modules that I already installed on my MacBook. For example,
from bs4 import BeautifulSoup
from requests import request
from tkinter import *
And the error message says,
No module named 'bs4'
File "/Users/my_name/Desktop/VsCode Projects/weather_detecter/main.py", line 7, in
<module>
from bs4 import BeautifulSoup
Also, it says the same thing on requests, but not on tkinter. I tried sudo pip, -m, pip3 on both terminal.app and VsCode terminal, but the outcome is still the same. How can I fix this?
You might need to select the correct python interpreter version first and then try importing the modules.
OR, open terminal in VS Code and try reinstalling the modules with the command python3 -m pip install <module_name>
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
I installed Python using Homebrew, I installed Pip and then using Pip I downloaded the Requests module.
Just to double check I tried to install it again and got a confirmation in terminal that it was already installed:
Requirement already satisfied: requests in /usr/local/lib/python2.7/site-packages
I then tried to write a pretty simple script to call Git and see if I can get a response. But when I run it I get an error message. Here's the script and message:
import requests
response = requests.get('https://api.github.com/events')
print (response)
Message:
PythonTesting/main.py", line 5, in <module>
import requests
ImportError: No module named requests
I'm a beginner in programming. Today, I was in the same problem. I spent many hours trying fix this problem. For me worked:
open prompt comand
cd (path of scripts directory in venv - my project on VisualStudio Code)
pip install requests
Then, I opened VS and put my code to go. It's work well.
Make sure you are running the code in version 2.7 as you have installed the request package for 2.7 only. If by mistake you are running the code on version 3, then that request package won't work. In that case, you need to install the requests for python3.
When I am trying to install tweepy module for python on windows 7, I type in easy_install tweepy
and it gives me the error of:
ImportError: No module named pip.req
I already read the link below but I am a newbie and didnt understand it:
No module named pip.req
PLEASE HELP!!
You should look inside the file setup.py in your folder with downloaded tweepy.
There you could find the line:
from pip.req import parse_requirements
setup.py tries to import parse_requirements function from module req from package pip.
But inside tweepy folder there are no pip package with req.py python module. Read about Python packages and modules here.
So you need to do the steps from the answer https://stackoverflow.com/a/25193001/821093 to fix it.
You can do a simply one line command as suggested by Tweepy installation
Or you can download the file yourself and put on your desktop (or wherever you like). From the windows command type:
cd deskstop\tweepy-master # tweepy-mast is defaul name from the zip download
python steup.py install
You can access the command prompt window using the "Window key" + "R" then type "cmd".
I'm very new to python and any non-basic computer functions in general, but I'm having a very basic problem and I can't figure out how to fix it. Any time I download a module from the internet and try to import it in python, I get an error message. For example, I just downloaded wxPython after being instructed to do so on a tutorial program for Python I've been using, and after entering "import wx" I got:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import wx
ImportError: No module named wx
How do I fix this so that python can find modules I download?
Thanks!!
Python version 2.7.3, and I downloaded wxPython from the download link on the website. Another thing I noticed: whenever I type in python setup.py install in the Terminal, I get:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
can't open file 'setup.py': [Errno 2] No such file or directory
Which seems to be another huge problem?
There are a few things you need to do to actually debug this:
Run python and check what version you are running.
type where python and figure out if you have multiple versions of python running at once.
With pip or easy_install, read the output to check where they are installing packages. It's somewhat likely that they are installing to the system-wide Python 2.6, as opposed to the version that you want it to be installed to (Python 2.7).
If you find any packages installed in the wrong place with 3, uninstall them with pip uninstall <packagename> and then specifically reinstall them to 2.7 with easy_install-2.7 or pip-2.7 install. If you don't see the option for easy_install-2.7 or pip-2.7, you need to install distribute and run its setup.py file with the specific version of Python you are using.
Make sure you are actually in the directory when running setup.py. For example, to install distribute, you need to cd into the appropriate directory to install.
Finally, a separate note: it's far easier to install packages with easy_install or pip, as opposed to downloading them separately. You should try doing that first. Again, distribute has more info.