I am using macOS 10.13.1 (which is the latest version at this moment) on a MacBook Pro 13" Early 2015, and am trying to install the "quora" library for python 3.6.1. I am trying to install it by typing this into the terminal:
pip install quora
When I do so, it says it is already installed. Then when I type into the python IDLE IDE:
import quora
As a single line program, it says that no module named quora is found, yet when my terminal specifically says it has already been installed.
Any information about how I can fix this will greatly be appreciated. Thank-you.
Edit #1:
When I input in terminal:
pip3 install quora
And I run the import in IDLE, it gives this error message:
Traceback (most recent call last):
File "/Users/Hussein/Downloads/quora_install.py", line 1, in
import quora
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/quora/init.py", line 8, in
from user import User, Activity
ModuleNotFoundError: No module named 'user'
Edit #2:
Up until this point I have been using the IDE for Python 3.6. I tried to run the import in Python 2.7, which is the default for the Mac, and works fine. But I do not know if there are functions that I need that may have been added to Python after the 2.7 release. I still wish to continue trying to get it work for v3.6.1.
Do you have multiple Python versions on your machine? Try pip3 install quora?
Related
I realize this question might come off as an easy fix, but it has been annoying me for the last hour. I'm new to working in a Python environment on my Mac, and I can't seem to install the tweepy module in the directory that I'm working in.
First I installed Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Next I installed Python:
brew install python
Which resulted in:
Python has been installed as /usr/local/bin/python3
Then I attempted to install the Tweepy package within the path /Desktop/twitterBot:
pip3 install tweepy --user
Which resulted in:
Successfully installed tweepy-3.9.0
After this I wanted to check that the Tweepy package was successfully installed, so within my bot.py file, the only line I wrote was import tweepy
When attempted to run my code python bot.py within the path Desktop/twitterBot, I receive the error:
Traceback (most recent call last):
File "bot.py", line 1, in <module>
import tweepy
ImportError: No module named tweepy
I really appreciate your guys' help. Thanks.
As explained, you're running your code with a different version of Python than the one you installed Tweepy for.
Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple.
Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
https://docs.python.org/3/using/mac.html
Since you installed Tweepy for Python 3 with pip3, you'll need to use python3 to run your code.
See https://docs.brew.sh/Homebrew-and-Python.
I'm using Windows 10, Python 3.6.4. I'm trying to use the module Pyperclip and have installed it with pip:
c:\Users\Bertie>pip install pyperclip
Requirement already satisfired: pyperclip in c:\python36\lib\site-packages (1.8.0)
But when I try to run a program which uses this module, I get this error:
c:\Users\Bertie\scraping.py test
Traceback (most recent call last):
File "C:\Users\Bertie\scraping.py", line 3, in <module>
import webbrowser, sys, pyperclip
ModuleNotFoundError: No module named 'pyperclip'
How can I fix this? Thank you.
The reinstall trace shows you install the packge successflly for python36.
Check if there is more than one python in your system. Type "python" in your windows cmd console, and check the python version to see if python36 is the default one. Then explicitly use the python interpreter to start the script "python your_python_script.py".
Where is the py file? Maybe try cd-ing into the folder and run python (python3) scraping.py?
Also check that you have installed the correct interpreter and are using the correct version of python.
Maybe You Installed pyperclip in conda env or a virtualenv and you forgot to activate it ?
Because This Has Happened To Me Many Times.
Or Maybe You Have 2 Instances Of Python installed on your computer and you accidentally installed pyperclip in the other instance of python ?
I'm a Python beginner working with Spyder, who must pip install modules for my class; pygal, for example. When I try to install, or reinstall as an administrator, this is what I get:
C:\WINDOWS\system32>pip install pygal
Requirement already satisfied: pygal in c:\users\flora\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (2.4.0)
Yet when I try to import the module in a Spyder file, this is the message I get:
Traceback (most recent call last):
File "C:\Users\flora\crash python\data mining\world_population2.py", line 2, in
import pygal
ModuleNotFoundError: No module named 'pygal'
And there's no sign of it in the dependencies in Spyder. Same thing using IDLE 3.8. I had assumed that Spyder or Anaconda would automatically be able to use it. Does it have something to do with WHERE I have saved it? I have tried reinstalling Anaconda, restarting my computer, etc. No difference.
Thanks in advance for any ideas.
No idea if this will help but if you goal is to use pygal you can try using a different ide with python build in. It does not run the most current version of python by default but you can change it to the version of python you have installed.
Try using Thonny I was able to import and run some code from pygal.
As some brief background information: I was origianlly trying to use Miniconda (with conda) to install dependencies that I need for my project on my Raspberry Pi. After trying to use Conda to install the SimpleAudio package, I got an error saying that it did not exist, therefore I proceeded to install this through Pip. Pip found the correct package although I get the following error message:
pi#raspberrypi:~ $ pip install simpleaudio
Traceback (most recent call last):
File "/home/pi/miniconda3/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
from pip._internal.models.target_python import TargetPython
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/models/target_python.py", line 4, in <module>
from pip._internal.utils.misc import normalize_version_info
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/utils/misc.py", line 20, in <module>
from pip._vendor import pkg_resources
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 92, in <module>
raise RuntimeError("Python 3.5 or later is required")
RuntimeError: Python 3.5 or later is required
It seems I need to update Python, although when I print the verion on Spyder IDE, it says I am already using 3.7.
Have I caused some sort of mismatch between what version my IDE is using and what the default process the terminal uses to look up the version? I noticed that it is looking for the Python version under Miniconda. If I can update If so is there a fix for this?
Please as me for more information if required (I am fairly new to stack overflow).
UPDATE:
I have been able to install the updated version of Python to 3.6 using the following instructions:
https://stackoverflow.com/a/56852714/12361146
This generally solves the scope of this question in terms of how I update Python, but I am still confused as to why Spyder IDE uses a more up-to-date version of Python whereas the terminal shows otherwise.
To answer the question of why Spyder reports a more up-to-date version of Python, here's the reason. The default versions of Python that are installed with Raspbian are 2.7 and 3.5, located in the /usr/bin/ directory. When you install Spyder, however (either independently, or more commonly, using conda), it includes its own installation of Python, which it is configured to use in the IDE, and which is located in a different directory. Hence when you compare the versions, first by entering python3 --version on the command line, and then print(sys.executable) from the Spyder IDE, they're different.
Now the issue with using pip alongside conda for updating the Spyder installation of Python is that it has the potential to mess it up quite badly, so avoid that unless you really know what you're doing. From code you posted above, you have avoided that, though, since that will have impacted the default Raspbian installation of Python, not the Spyder one. Upgrading the latter version should be done using Conda, not pip.
Hopefully you're now all up and running.
You can install newer versions of python using the package manager apt or apt-get.
Start by getting up-to-date package definitions.
$ sudo apt-get update
Then you can show details about the python3 package.
$ apt-cache show python3
When I run that now I get "Version: 3.7.3-1".
To install the python3 package and all its dependencies.
$ sudo apt-get install python3
You will still need to type python3 and pip3 when you run the commands because you are not replacing the built-in python 2.7.
Try these commands to see what you get
$ python --version
$ python3 --version
If you want to change the default python to python3 then have a look at this answer How to change the default python version in Raspberry Pi
I am coding on Python 2.7. I want a large list of words to have access to. Looking around, I have found that nltk has what I'm looking for. However, every time I try and install it I get a syntax error. I have tried doing the commands in the shell and in files. I have no true understanding of how pip, install, and download commands work. I am on a mac, which other threads have said could affect things. I have tried...
sudo pip2 install nltk
Which gives:
SyntaxError: invalid syntax
When importing, I get
import nltk
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import nltk
ModuleNotFoundError: No module named 'nltk'
nltk.download
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
nltk.download
NameError: name 'nltk' is not defined
and a few other suggestions from other threads, but nothing works. Please help.
pip is your python package manager. It is a command line tool, and not a python function, object or method. This means you can't call pip from within python (at least not by just typing pip ... into a python interpreter). pip should come along with your installation of python 2.7, so you don't need to install it, as long as you have python installed.
You need to call pip from your command line (on a mac, this would most likely be from terminal). So you need to open your terminal, type pip install nltk, which should install your package.
Then, you can start python by using the command python in terminal. You can then import nltk using import nltk.
Only once you've followed those steps, and successfully installed and imported the nltk package, can you use nltk.download() to download nltk data. nltk.download() in itself has nothing to do with installing the package.
I would recommend following a python tutorial, such as the one linked, in order to gain an understanding of how to use the python interpreter. This should explain how to install packages, and use basic python functionality.
Most versions of Mac OS come with Python version 2.7, but not with pip.
First verify that you have pip installed from the command line:
pip -V
If pip is not installed, follow the instructions here:
How do I install pip on macOS or OS X?
Then, directly in the terminal type (not in the python interpreter)
pip install nltk
Then, open your python interpreter from the command line:
python
and in the python interpreter, try importing nltk
import nltk