Installing python package - python

I've already installed mechanize using pip install mechanize, such that when I enter it in the command prompt, the response is: Requirement already satisfied: mechanize in c:\users\wwl\anaconda3\lib\site-packages.
However, when I type import mechanize in the jupyter notebook, it gives an error:
ImportError: No module named '_mechanize'.
Where have I gone wrong?

Are you using Virtualenv?
If so, make sure you are importing the global libraries to your virtualenv (https://virtualenv.pypa.io/en/stable/userguide/#removing-an-environment).
If not, probably your Python version is not compatible. https://stackoverflow.com/a/24001585/2051397
Hope it helps

Related

failed to use urllib.request with python in vscode

I tried to import urllib.request wth python in vscode but kept getting the message: ImportError: No module named request. I have no problem importing just urllib, which I know is the right line for python2. I'm sure I'm using python3 as that's what I've selected in the interpreter path.
Here's the screenshot:
I've also put pip3 install urllib3 in the terminal and got this message which means python3 should have it:
Requirement already satisfied: urllib3 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (1.26.9)
any idea what have gone wrong or it's not the problem with python version?
This is related to your multiple environments. You should specify the installation path when using pip installation package.
pip install -t flodername urllib3 #the package of the python interpreter you chosen

What is the reason of ModuleNotFoundError: No module named 'mysql' in Python 3.8.10 and Requirement already satisfied in anaconda location problem?

I need to import mysql-connector and I installed it by using pip install mysql-connector-python.
After the installation, I can see the same error is displayed.
After that again I tried to install mysql connector, but it displayed that Requirement already satisfied and show a path in anaconda lib folder.
Is there any effect from previous installation on Anaconda and how to import mysql-connector to code?
As a solution for that, I changed the interpreter of the code into ('base': conda). It worked correctly without any error.

import bs4 ModuleNotFoundError: No module named 'bs4'

I am trying to create a web script, but when I run it it gives me this error:
import bs4 ModuleNotFoundError: No module named 'bs4'
When I go to my project interpreter, bs4 and beautifulsoup4 are installed. Also, when I run the command pip install beautifulsoup4, it says that:
Requirement already satisfied: soupsieve>1.2; python_version >= "3.0" in ./venv/lib/python3.8/site-packages (from beautifulsoup4) (2.1)
My Python version is 3.8.0.
Try to run this command in the same interpreter as your python script.
pip install beautifulsoup4
You may have more than one interpreter setup on your machine, and when you type the command it does not install to the interpreter/virtual environment where your python script is running.
Solution
Follow the following steps in order, if applicable to your situation:
If you are using an IDE, such as Pycharm or VSCode, you will have an option to choose your virtual environment. Keep note of the name of the environment.
Then, activate your virtual environment, and install the package using the command I specified above. This process can be done from the command line or IDE
Run your python script in that environment/interpreter
This should have liberally answered the question, but if you want to learn more about virtual environments and interpreters, then use this link.
https://realpython.com/python-virtual-environments-a-primer/
I use PyCharm Python3.7 , is ok.
Python3.8 should be fine.
pip3 install beautifulsoup4
from bs4 import BeautifulSoup

ModuleNotFoundError using pip

I have installed the module alpha_vantage using pip. In CMD writing import alpha_vantage does not show an error message, so I assume it is installed properly.
However, when trying to import alpha_vantage in a python program I get this error: "ModuleNotFoundError: No module named 'requests'". I assume the issue is due to the location of the module.
The project is located here:
C:\Users\M\Documents\Python\Investering.
I tried placing the module here by pip: C:\Users\M\Documents\Python\Investering\modules\alpha_vantage
Note pip did not install the module there I simply copied the module folder and placed them in the project folder.
Is it possible to simply copy and paste module folders in other projects? Or how am I supposed to make python acknowledge the module?
The module was installed here:
C:\Users\M\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\alpha_vantage
I'm quite new to python. I have tried adding to sys.path the folder where the module was installed, but it did not seem to help.
Thanks for any help.
Edit: I tried pip install requests and it produced this:
Requirement already satisfied: requests in c:\users\martin\appdata\local\programs\python\python38-32\lib\site-packages
Someone mentioned running: "pip install foo"
It, however, produces this error message:
ERROR: Could not find a version that satisfies the requirement foo (from versions: none) ERROR: No matching distribution found for foo
I am using PyCharm.
I found my error. I had installed python from the website, but had unknowningly installed the 32 bit version, and a 64 bit version. I uninstalled all my python versions and pycharm. Then I reinstalled everything. Now I could easily make the module work. Thanks for the pointers.

How to fix "No module named 'nredarwin'" ImportError in python

I'm trying to access the Darwin feed from National Rail Enquiries in Python 3.5.3 on my Raspberry Pi. I'm trying to use a module called nre-darwin-py but after I've installed it using pip install nre-darwin-py (with and without sudo) I'm getting an ImportError when I try to import it in my program when using Python 3 (IDLE).
However, when I run python inside the command prompt I am able to import the module and try to use it, it works! I am also able to run some of the provided example code in the command prompt but not inside Python 3.
The code I'm using to import it is:
from nredarwin.webservice import DarwinLdbSession
but that's copied straight from the example code provided.
The code is running in a file called nre testing.py in /home/pi/Station Departures. From questions I've previously found here, the module has been installed in /usr/local/lib/python2.7/dist-packages/ which I think is what's causing the problem as I'm running Python 3.5.3.
I've tried installing the module using python -m pip install nre-darwin-py with and without sudo but the command prompt returns
Requirement already satisfied: nre-darwin-py in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: suds-jurko in /usr/local/lib/python2.7/dist-packages (from nre-darwin-py)
So the pi thinks that the module has been installed successfully (suds-jerko is a required module it installs)
I'm afraid I have so far been unable to find a solution so any help is most welcome.

Categories

Resources