Python can't find already installed module robobrowser - python

I am trying to create a very simple Python 3.6 script. Using MacOS.
For this script I had to install robobrowser, which I installed with easy_install robobrowser. After that I try to import it with the following statements:
import re
from robobrowser import RoboBrowser
However, terminal prompted me with the following (infamous) error:
Traceback (most recent call last):
File "signup.py", line 2, in <module>
from robobrowser import RoboBrowser
ModuleNotFoundError: No module named 'robobrowser'
I have installed Python 3.6. However, in my /Library/Python I only have 2 folders: 2.6 and 2.7. In /Library/Python/site-packages there is a folder named robobrowser-0.5.3-py2.7.egg. Might it have something to do with this?
Sorry for asking a most likely easy question. I can however not seem to figure it out.
Thanks for reading this,
Thijmen.

Probably you are using easy_install for Python2. The best solution is to install pip for Python3 and run pip install robobrowser

This must be because you have multiple versions of Python installed, and when you installed robobrowser, it got installed to a different python version than the one you are trying to use. If you want to use it with Python 3, make your $PATH variable use the Python3's Scripts path instead of the one from Python2. Or a simpler way is to install pip3 on your computer and do sudo pip3 install robobrowser
For reference: changing python path on mac?
You can run the which python, which python3 and which easy_install commands in your terminal to find which versions of python and easy_install are being used by default.

Related

How to install troposphere for python3?

I'm running macOS version 11.0.1.
I'm trying to import a module called troposphere
I have Python2.7 as well as Python3.9.1 installed
When I try to import troposphere using Python2.7 like
#!/usr/bin/python
from troposphere import Template
It does work. But when I try to import the same using Python3.9.1 like
#!/usr/bin/python3
from troposphere import Template
It throws error like this
ModuleNotFoundError: No module named 'troposphere'
What should I do? Please help
it is because the python interpreter you use to run your code doesn't have troposphere installed.
Managing multiple Python version on the same computer is tricky, But I will try to explain it.
I assume that you are using python your_script.py to run your code, and pip install troposphere to install package right? But think of this, how does your system know exactly which python you are running and which python to install package? Here's how to check the full path of your python command and pip command.
type python command enter python console
then type this:
import sys
print(sys.executable)
3. navigate up and down little bit, you will find a bin folder include bin/python which is your interpreter and bin/pip which is your pip command. And there's a lib/site-packages folder, this is where third party library been installed to.
4. if you see import error, use the above method to locate the python interpreter and check the site-packages folder, most likely there's no such troposphere folder in it. Then you need to use the full path of the <path-to>/bin/pip to install troposphere. Then your problem is solved.
If you are using home brew or the python installer download from www.python.org, your system probablly already messed up. The recommended way to manage multiple Python version is to use pyenv https://github.com/pyenv/pyenv. It allows you to install any python version and easy to delete them.
Chek if the module was depreciated

Python Libraries installing to Python 2.7 by default

I recently shifted to a Macbook. I installed Python 3.8 and installed Pyperclip using pip install pyperclip in the terminal, which was successful. When I tried to import it in IDLE shell, I get the error
ModuleNotFoundError: No module named 'pyperclip'.
On looking around I found that pyperclip has been installed in-
/Users/aamodpant/Library/Python/2.7/lib/python/site-packages/pyperclip
I did not install Python 2.7 but it must be required for macOS, so I don't want to delete it. How do I change the "default" version of Python for installing new libraries?
Use :
python3 -m pip install pyperclip
This will install the package for python3.
You can reinstall or upgrade pyperclip using sudo:
pip3 install -U pyperclip
Also, run your script using python3 instead of just python:
python3 script.py
The best is to use alias, as this answer describes changing default Python version in Mac can cause multiple issues.
alias python=python3
alias pip=pip3
The answer you are probably looking for is You should not change this.
Otherwise, you may like to set Python 3 as default, there are many ways to do it. But do it with caution as the guides suggest below.
The official documentation: Using Python on a Macintosh, some well described very good guides: The right and wrong way to set Python 3 as default on a Mac, Installing Python 3 on Mac OS X.

ModuleNotFoundError: No module named 'yyy' in Windows Shell

I'm using Python 3.6 on Windows 7.
I have a script that uses standard python packages.
The script run fine from IDLE.
It used to run fine from Windows command too, but not anymore.
I don't know why. It complains about missing package like:
, line 4, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
The path looks ok (I've added all path found from IDLE / Path Browser):
PATH=C:\Users\olivier\AppData\Local\Programs\Python\Python36\lib\site-packages;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Lib;C:\Users\olivier\AppData\Local\Programs\Python\Python36\DLLs;C:\Users\olivier\AppData\Local\Programs\Python\Python36\python36.zip;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\olivier\AppData\Local\Programs\Python\Python36\;C:\Users\olivier\AppData\Local\GitHubDesktop\bin
Any idea?
Thanks
I had the same problems. Did you try to install it through pip and did you try to install on the strict path by using pip install --target="..." for e.g "pip install --target=C:\U2\UV\python\Lib\site-packages geopy" and pasting it in python console?
Also look at this post: Install a module using pip for specific python version
These two points can help you to solve the problem as per my knowledge.
Are you using two Python versions?
Check the Environmental Variables and if everything is fine there, it's better to uninstall and reinstall it again. use pip for installing and uninstalling

Trying to install a pack from source. I get: ImportError: No module named requests Yet the pack is installed

I'm trying to install: https://github.com/rozzac90/pinnacle.git from source.
If I type sudo python setup.py install (or sudo python setup.py configure) I get:
import requests
ImportError: No module named requests
The module is installed, I'm sure. It is in the list of conda installed packs. Also, if I try to import it in other scripts, and
python
>>> import requests
>>>
with both python 2 and python3. I get no errors.
I also removed it and installed it again. Same results.
I am using Anaconda with a python3 environment. (I get the same errors in python 2, though.) So I can't use pip commands. I'm running a lubuntu machine, latest version.
Ideas anyone? Thanks in advance !
A suggested answer :
The solution was to run the script in the folder where setup.py is located, in general :
Try with
sudo /[annaconda_python_path]/python setup.py install
Make sure the right environment is active in the terminal.

python module already installed elsewhere

Im trying to use the pyperclip module in the idle python editor. When I try to import I get an error saying:
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
When I try to pip install pyperclip in terminal, I get the following:
Requirement already satisfied: pyperclip in /anaconda3/lib/python3.7/site-packages (1.7.0)
Im brand new to learning python and developing in general, so sorry if this is an easy solution or covered elsewhere that I could not figure out how to find. Im still learning how to most effectively use python so I'm not sure which editor or system I prefer yet. Is there a way to be able to use the pyperclip module in idle without deleting it from anaconda, or removing anaconda entirely?
Im running python 3.7.2 on a Macbook with macOS Mojave 10.14.3.
Thanks!
In terminal, the following
$ python3 -m pip install pyperclip
or similar should install pyperclip or other modules to the python3 installation, where it can be found when you run IDLE with
$ python3 -m idlelib
I expect the same to be true when you start IDLE from the icon or python launcher, but I don't know what changes Anaconda makes to your system.

Categories

Resources