Selenium installed in python, but still can't import module? - python

I'm using linux mint. I installed selenium using pip, and it finished with no problems. Then I ran python and tried to check that selenium works:
ethomas#ethomas-linux ~ $ python
Python 2.7.9 (default, May 19 2015, 13:47:37)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named selenium
then in python I did:
>>> import sys
>>> sys.executable
'/usr/local/bin/python'
>>> sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
I ran $ locate selenium and it's all found in /usr/local/lib/python2.7/dist-packages/selenium. Yet I still can't import selenium in python. Anyone know what the problem might be? It may have something to do with the sys.path but I'm not sure.

I had installed python 2.7.9, while the default is 2.7.6 on my box, so it put it into usr/local/bin and was causing the error. Deleting it from usr/local/bin fixed the probelm.

Related

Python module **slackclient** installs correctly, but will not import ... is it known under another name?

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.

Python is trying to import modules from a different version of Python. Rearranging Python versions in PYTHONPATH fixes it. How to make this permanent?

I have both Python 2.7 and Python 3.5. Below I have run Python 3.5, but it is looking for modules in Python 2.7. Pandas is installed for both Python versions. In order to fix this, I can rearrange the python versions in PYTHONPATH, but then Python 2.7 won't work. I want both Python versions to be able to pick up Pandas.
ubuntu#ip-abc: python3
Python 3.5.2 (default, Jan 26 2021, 13:30:48)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pandas/__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
>>> import sys
>>> sys.path
['', '/home/ubuntu/automation', '/home/ubuntu/automation/simulation', '/home/ubuntu/aws_batch_client', '/home/ubuntu/temp', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python3/dist-packages', '/home/ubuntu/automation/modelpool', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/home/ubuntu/.local/lib/python3.5/site-packages']
This is what my PYTHONPATH looks like:
/usr/local/lib/python2.7/dist-packages:/usr/lib/python3/dist-packages/:/usr/local/lib/python3.5/dist-packages
This is a slightly different version of my problem but the solution listed here doesn't work for me: Why python3.4 is trying to import module form python2.7
The solution, thanks to #Ghoti and #tdelaney from the comments: Clear the PYTHONPATH. You could export PYTHONPATH= to clear it.

How can I use globally installed CV2 (manual install) package into python virtual environment?

I have manually installed CV2 on Ubuntu box, and when I import CV2 it works perfectly.
If I create virtual environment (python -m venv myvenv), I am not able to use globally installed CV2.
Kindly advice the fix, to use global installed packages into python virtual environment.
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>>

Importerror: No module named time in python2.7.6 in ubuntu

I have a strange problem on python2.7.6 with Ubuntu :
my python 2.7.6 is installed but strangely time module is not working. my ubuntu version is 16.04
i tried installing python 2.7.16 as well but that didnt fixed the issue as
/usr/local/bin# python2.7
Python 2.7.6 (default, Jul 22 2019, 12:49:04)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named time
expected : import time should work
actual : ImportError: No module named time
How do i import time in python 2.7.6
output of :
: ls /usr/lib/python2.7/lib-dynload/
audioop.i386-linux-gnu.so _codecs_tw.i386-linux-gnu.so dl.i386-linux-gnu.so _lsprof.i386-linux-gnu.so Python-2.7.egg-info
audioop.x86_64-linux-gnu.so _codecs_tw.x86_64-linux-gnu.so _elementtree.i386-linux-gnu.so _lsprof.x86_64-linux-gnu.so readline.i386-linux-gnu.so
_bsddb.i386-linux-gnu.so crypt.i386-linux-gnu.so _elementtree.x86_64-linux-gnu.so mmap.i386-linux-gnu.so readline.x86_64-linux-gnu.so
_bsddb.x86_64-linux-gnu.so crypt.x86_64-linux-gnu.so fpectl.i386-linux-gnu.so mmap.x86_64-linux-gnu.so resource.i386-linux-gnu.so
bz2.i386-linux-gnu.so _csv.i386-linux-gnu.so fpectl.x86_64-linux-gnu.so _multibytecodec.i386-linux-gnu.so resource.x86_64-linux-gnu.so
bz2.x86_64-linux-gnu.so _csv.x86_64-linux-gnu.so future_builtins.i386-linux-gnu.so _multibytecodec.x86_64-linux-gnu.so _sqlite3.i386-linux-gnu.so
_codecs_cn.i386-linux-gnu.so _ctypes.i386-linux-gnu.so future_builtins.x86_64-linux-gnu.so _multiprocessing.i386-linux-gnu.so _sqlite3.x86_64-linux-gnu.so
_codecs_cn.x86_64-linux-gnu.so _ctypes_test.i386-linux-gnu.so _hashlib.i386-linux-gnu.so _multiprocessing.x86_64-linux-gnu.so _ssl.i386-linux-gnu.so
_codecs_hk.i386-linux-gnu.so _ctypes_test.x86_64-linux-gnu.so _hashlib.x86_64-linux-gnu.so nis.i386-linux-gnu.so _ssl.x86_64-linux-gnu.so
_codecs_hk.x86_64-linux-gnu.so _ctypes.x86_64-linux-gnu.so _hotshot.i386-linux-gnu.so nis.x86_64-linux-gnu.so termios.i386-linux-gnu.so
_codecs_iso2022.i386-linux-gnu.so _curses.i386-linux-gnu.so _hotshot.x86_64-linux-gnu.so ossaudiodev.i386-linux-gnu.so termios.x86_64-linux-gnu.so
_codecs_iso2022.x86_64-linux-gnu.so _curses_panel.i386-linux-gnu.so imageop.i386-linux-gnu.so ossaudiodev.x86_64-linux-gnu.so _testcapi.i386-linux-gnu.so
_codecs_jp.i386-linux-gnu.so _curses_panel.x86_64-linux-gnu.so _json.i386-linux-gnu.so parser.i386-linux-gnu.so _testcapi.x86_64-linux-gnu.so
_codecs_jp.x86_64-linux-gnu.so _curses.x86_64-linux-gnu.so _json.x86_64-linux-gnu.so parser.x86_64-linux-gnu.so
_codecs_kr.i386-linux-gnu.so dbm.i386-linux-gnu.so linuxaudiodev.i386-linux-gnu.so pyexpat.i386-linux-gnu.so
_codecs_kr.x86_64-linux-gnu.so dbm.x86_64-linux-gnu.so linuxaudiodev.x86_64-linux-gnu.so pyexpat.x86_64-linux-gnu.so
It seems time package is not install, you can try by installing time package using below command.
pip install times
or
sudo pip install times.
and then try?

Cannot import gnureadline package in Python3.x (Mac OS)

I have successfully installed gnureadline using both pip (2.x) and pip-3.5. Although importing it in Python2.7 works perfectly, in Python 3.5 it throws the following exception:
Python 3.5.1 (default, Jan 31 2016, 04:03:04)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnureadline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so, 2): Symbol not found: _PyInt_AsLong
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so
The weird thing is that python looks for the package in the Python2.7 path.
The platform is OSX 10.11.3.
You have to check your PYTHONHOME env variable.
check it with echo $PYTHONHOME, it should point to 3.5 version ,
if it's not true, fix it by the following command
export PYTHONHOME=/full path to appropriate python libs/
After checking the sys.path variable as BasicWolf pointed out, I noticed that the 2.7 site packages were included independent of the python version that I run. This happened due to an override of the PYTHONPATH env variable in my .bashrc file:
export PYTHONPATH=~/Library/Python/2.7/lib/python/site-packages/

Categories