I installed a Python module using pip. When I tried to import it, I got this error:
Traceback (most recent call last):
File "Untitled.py", line 1, in <module>
import watson_developer_cloud
ModuleNotFoundError: No module named 'watson_developer_cloud'
What can I do to fix this?
I am using macOS Mojave 10.14.2 (beta), pip 10.0.1 (I also tried to upgrade it to 18.1, but after the install the version stayed the same).
You probably installed it with sudo, so it's not accessible when you run the script without sudo. Anyhow, it's really messy to install modules directly. And it's dangerous to install modules to systems python.
Install a brew version of python and pip. then create a virtualenv and install your packages in it. It's much safer and portable.
Read this answer No module named 'pafy'
Please don't run the script as sudo to make it work, especially if you are not the one who wrote it. Use a virtualenv instead.
Related
I am using manjaro linux.
I tried to install OpenGL python library. I ran
pip install PyOpenGL PyOpenGL_accelerate
It seemed to work fine, and said it had installed. When I ran import OpenGL in PyCharm it simply returned
/home/jackgreen/PycharmProjects/openGLtest/venv/bin/python /home/jackgreen/PycharmProjects/openGLtest/main.py
Traceback (most recent call last):
File "/home/jackgreen/PycharmProjects/openGLtest/main.py", line 1, in <module>
from OpenGL import *
ModuleNotFoundError: No module named 'OpenGL'
in the console.
By the look of your path /home/jackgreen/PycharmProjects/openGLtest/venv/bin/python
It looks as if you are running from a virtual environment. However you don't specify if you have activated this environment before doing the PIP install.
See the python docs here
You need to activate the environment then do the PIP install.
As long as your virtual environment is activated pip will install packages into that specific environment and you’ll be able to import and use packages in your Python application
Try
source /home/jackgreen/PycharmProjects/openGLtest/venv/bin/activate
Then do the PIP Install
I am using Ubuntu Server 18.04 LTS(HVM)-free tier to run my python script. I connect with the Key to the server with Putty. I manage my files loaded onto the the server using FileZilla. After I install python on the server with sudo apt install python3 I install Selenium using pip install -U selenium. The process is a success. I then load my python script through FileZilla and then try to run the python script. Like most that have asked I get the error:
Traceback (most recent call last):
File "BinaryAutomation.py", line 1, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
Now please understand this. I have tried to install selenium manually by installing and unachieving the file found here, which basically downloads the setup to be loaded using python setup.py install. I do not have permission to paste anything under tmp\usr\bin I have tried that. How do i get around this problem?
You probably have other versions of python/pip installed. Install packages using pythonx -m pip install ... with pythonx your python version (python3 I presume) to avoid installing packages for a version of python that you're not using to run your scripts.
For more details check: Why you should use python -m pip - Snarky
Ubuntu generally follows PEP 394, which says that the command python should be Python 2. So, use python3 instead of python. That extends to PIP too, so I would say to use pip3 instead of pip, but that method is becoming outmoded; use python3 -m pip instead.
This is assuming you haven't changed the python and pip commands.
I wrote a script to call an API and ran it successfully last week. This week, it won't run. I get back the following error message:
Traceback (most recent call last):
File "user_audit.py", line 2, in <module>
import requests
File "c:\Python27\lib\site-packages\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "c:\Python27\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
I've confirmed that packages is up to date, tried uninstalling and reinstalling it, but nothing has worked so far. Can someone help?
ADDENDUM
I installed urllib3 as suggested by #MSHossain, but then got another error message. The new message referenced another file that I'd written, which had created a Python compiled file. The other file was using smptlib to attempt to send an email. I don't understand how this would happen, but I deleted the other file and my script ran without any problems. I've accepted the answer below as I was able to pip install urllib3, but it should have already been included in the requests module.
Either urllib3 is not imported or not installed.
To import, use
import urllib3
at the top of the file. To install write:
pip install urllib3
into terminal.
It could be that you did not activate the environment variable correctly.
To activate the environment variable, write
source env/bin/activate
into terminal. Here env is the environment variable name.
pip install urllib3
The reason it broke is that I had installed an incompatible version of urllib3 as a transient dependency of awscli. You'll see such conflicts when you rerun the install.
I solved it by running
pip install --upgrade requests
set you environment by writing source env/bin/activate if env not found write virtualenv env first then source env/bin/activate , then check pip freeze if urllib3 not found there then reinstall urllib3, hope it helps.
I already had it installed. Solved it by running pip install --upgrade urllib3
Hope it helps someone :)
Few minutes back, I faced the same issue. And this was because, I used virtual environment. I believe that due to venv directory, the pip installed might have stopped working.
Fortunately, I have setup downloaded in my directory. I ran the setup and chose the option to repair, and now, everything works fine.
For me in PyCharm I had to put import urllib3 at the top of the file as mentioned earlier then PyCharm gave the option to import. Even after installing it with pip
Reinstalling urllib3 solves my problem. Run:
pip uninstall urllib3
pip install urllib3
For the sake of completness. It means the python installation you are using does not have the package installed, be sure you are using the same python installation as the one where you are installing the package.
For me what was happening is that I had a virtual environment made with pyenv, even when the virtual environment had the package installed and in its latest version, it was not found because somehow the underlaying python install was used and not the one where I had the urllib3 installed.
Solution: Use the absolute path to the python binary:
/home/[username]/.pyenv/versions/[envname]/bin/python python-script.py
I have cloned the git repository of flask(https://github.com/mitsuhiko/flask). I run Python 3.4.1 on both my windows and ubuntu machines. To install flask(on windows), I just change directory to flask repository on my machine and run python setup.py build install . Flask successfully installs and runs. When I try repeating the same steps on ubuntu, it simply throws an error saying
Traceback (most recent call last):
File "flask_example.py", line 1, in <module>
from flask import Flask
ImportError: No module named 'flask'
I tried installing flask through pip, pip install flask and by using "virtualenv" with easy_install as well. I still get the same error. Can anyone tell me what the issue could be?
In all Ubuntu versions so far, pip command defaults to one that installs packages for the latest Python 2 version installed, i.e. most probably Python 2.7; this is the python that will start with python command.
Python 3 instead is runnable as python3 or python3.4; there is a corresponding version of pip, such as pip3 (for the default Python 3 version), or pip3.4 for the pip that specifically installs the packages for the Python 3.4 versions.
Most notably, pip does not know anything about what are the possible aliases in the command shell (bash, zsh), and thus is completely oblivious to those.
This is a beginner python installation question. This the first time I have tried to install and call a package. I've got pip installed, and I tried to install two modules - numpy and pandas.
In terminal, I ran the following commands:
sudo pip install numpy
sudo pip install pandas
Both commands returned with a success message. Here is the pandas success message (it's the second package I installed and was still in my terminal history):
Successfully installed pandas
Cleaning up...
pip returned a similar message after numpy was installed.
Now, when I launch python and try to call it with:
import pandas
I get this error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
Same when I try numpy.
Can anyone tell me what I'm doing incorrectly?
argh. you've got two pythons in your path that are the same version? don't do that.
pip, easy-install, etc are associated with a particular python install and will use that python by default. so if you have a system-provided python and a system-provided easy_install (or installed easy_install yourself using the system python) then easy_install will, by default, install packages for the system python.
the best way to avoid this mess, imho, is to use use system python for that version (2.7 probably) and, for other versions, use make alt-install when installing, which will give you executables like python3.1 and the like. if you really need to replace the version provided by the system, uninstall it.
once you've done that. each python will have a distinct name (ending in the version) and python will remain the system one.
next, when you install easy_install, you'll notice that there are version-specific versions (easy_install-2.7 for example). use those. if one is missing, then install distutils with the appropriate python (eg use python3.1 and you'll get an easy_install-3.1). unfortunately, each time you do this (iirc) you overwrite the un-versioned easy_install, so never use that - always use the versioned one.
alternatively, you could not install easy_install or pip for anything other than the system version, then always use virtualenv. virtualenv will let you specify a python version (so you can use the system virtualenv for all pythons installed) and then installs easy_install/pip for the python you use. so once you're inside the virtual environment, everything just works.
and i just realised i haven't much experience with pip, so i can't actually help with that (except to note that virtualenv does provide it) (about which is preferable: it used to be that pip was better maintained; i think these days the latest distutils/easy_install is as good as pip, but pip has a few more features that i have never used).
disclaimer: the above is from experience gained developing lepl, which runs on 2.6 to 3.2, so i need to test it on all those. as far as i know, what i describe above works for me, but i have no deep knowledge of python/easy_install/pip so i may have some mistakes in rationalising/describing things (in other words, i'm writing all this in case it helps, but i'm a bit worried i have an error - please, someone correct me if so).
With this, I solve the problem (may help you):
$ sudo apt-get install python-pandas
$ sudo apt-get install python-numpy