I wrote a basic Python 3 script that uses the Google Sheets API. It works on a system that defaults to Python 3 (Arch). I'm trying to run the same script on an Ubuntu 14.04 system, but I'm unable to load the apiclient library. I installed with the recommended
pip install --upgrade google-api-python-client
But I noticed I can only load the library in python 2.
Here's what I'm observing:
~ $ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from googleapiclient import discovery
>>> quit()
~ $ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from googleapiclient import discovery
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'googleapiclient'
Any advice?
The Googleapiclient is installed only on python2 (Which i guess is your default python version) not python3.
Install Googleapiclient in python3 env using the following:
pip3 install --upgrade google-api-python-client
python -m pip install --upgrade google-api-python-client
Related
I am trying to get a module slackclient installed in a virtual Python environment.
python3 -m venv slackenv
. slackenv/activate
pip3 install slackclient
I get
python3.7
Python 3.7.6 (default, Jan 12 2022, 23:27:58)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import slackclient
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'slackclient'
This is with slackclient installed both in the virtualenv and in the main system pip list. (It shows up in both lists).
What could be the issue?
Despite the name of the package is slackclient, the actual module is slack, as can you see in the official page of the package. So, try this one:
import slack
it should work.
I have been using lirc in Python 2.7 and Python 3.5.3 on Rpi3. Now I have installed Python 3.8.7 from source code, but I am not able to use lirc in this version of Python, but it still works in Python 3.5. apt-get reports that python3-lirc is already the newest version (1.2.1-2). How to get lirc work in both Python 3.5 and 3.8?
pi#RPi3:~ $ python
Python 3.8.7 (default, Jan 7 2021, 08:59:27)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lirc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lirc'
>>>
pi#RPi3:~ $ python3.5
Python 3.5.3 (default, Nov 18 2020, 21:09:16)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lirc
>>> sockid=lirc.init("myProg", blocking = False)
>>>
It means that you installed lirc on only one of the two pythons.
Use the pip from your Python 3.8 to install lirc so that the module will also be accessible to your Python 3.8.
Module lirc has to be uninstalled with pip, then python-lirc can be installed in Python 3,8 as described in https://github.com/tompreston/python-lirc/issues/26 after installing cyhton with pip.
I downloaded the source code of python 2.7.14 and built it and installed it on linux ( Red Hat 4.8.5-16 ). I have earlier installed python-magic and requests libraries. Now when I try to import modules installed using pip, I get this:
$ python2
Python 2.7.14 (default, Nov 9 2017, 09:05:45)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named magic
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
while similar thing works perfectly fine in python 2.7.5 (default with the RHEL system)
$ python
Python 2.7.5 (default, May 3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
>>> import requests
>>>
Am I missing any configuration step here?
The modules installed via pip are only available to the standard python version. You need to install your desired packages for the non-standard python versions as well (see also Installing Python Modules)
python2 -m pip install python-magic
python2 -m pip install requests
your pip is default set for version
$ python
Python 2.7.5
SO if you want to install module for
$ python2
Python 2.7.14
use python2 -m pip install module_name
The sys.path must be different for the two installations. That's a list of folders that Python checks for imports.
It's probably simplest to just symlink the one for wherever pip installs to into the modules folder for 2.7.14.
I'm new to Ubuntu (14.04). I just installed django using sudo pip install Django.
This is what is happening:
rpr#rpr-Inspiron-3521:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
rpr#rpr-Inspiron-3521:~$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'django'
>>>
What should I do to be able to use Django from Python3.4?
Just write:
sudo pip3 install Django
But better use virtualenv like Daniel said.
Reference
If you cannot run pip3 install it with the following:
sudo apt-get install python3-setuptools
sudo easy_install3 pip
pip is presumably installed for Python 2, not Python 3. You may have a version named pip3 that targets Py3.
However, it would be better to use a virtualenv.
I've installed Python 3.3 alongside Python 2.75 on my Ubuntu machine. The problem is that easy_install gets packages for the default, 2.75 version only, e.g:
easy_install pymongo
$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>>
But:
$ python3.3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pymongo'
How can I install PyPi packages for the Python 3.3 installation?
You need easy_install3. In apt-get you get it by
apt-get install python3-setuptools