Installed Selenium on Ubuntu, but can't import it - python

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.

Related

Requests module for python not being recognized

I am on a Mac.
I installed the requests module to do some web scraping but whenever I run the file it is telling me that it doesn't recognize the requests module. I then checked if the module is installed and it was. I've attached a screenshot.
And here is the error message
File "scraper.py", line 1, in <module>
import requests
ImportError: No module named requests
The issue is with the different versions of Python I have. Mac ships with 2.7 by defualt and even though I installed the requests module it was installed for the default python version.
So what I did was
Installed the latest Python version
Changed the default Interpreter Path in Vscode . Here is the official Vscode guide https://code.visualstudio.com/docs/python/environments
And finally installed requests for Python 3 using this command in the terminal
sudo python3 -m pip install requests
You may need to update your pip too
pip install --upgrade pip
I still think I need to manage the Python environments better but that is for another time.

Python modules download in wrong folder

Whenever i download a module using pip or similar the modules go to my python2.7 folder instead of my python3.8 folder, and due to this whenever i run my code if there is a module not in my 3.8 folder which is in my code i get a ModuleNotFoundError,
eg just recently:
File "/Users/tvnsh/Library/Python/3.8/lib/python/site-packages/flask/app.py", line 34, in <module>
from . import cli
File "/Users/tvnsh/Library/Python/3.8/lib/python/site-packages/flask/cli.py", line 25, in <module>
import click
ModuleNotFoundError: No module named 'click'
I know i can just move it from the 2.7 to 3.8 but why is this happening?, and how do i get the modules to download straight to my 3.8 folder instead?.
PS im new to coding and python as a whole so I appreciate your help.
how do i get the modules to download straight to my 3.8 folder instead?.
You might make sure you are downloading to your current version of python (i.e. what is launched after typing python) by doing
python -m pip install click
and for python3 (version which is launched after typing python3) by
python3 -m pip install click
If you want to know more read Installing Python Modules.
If you are creating a virtual environment, the easiest way is to run
pipenv --python 3.8
Alternatively and as a more persistent solution, you can add the following lines into the pip file:
[requires]
python_version = "3.8"
You are probably using the wrong version of pip.
Check if you have something called pip2 for python 2.x and pip3 for python 3.x
Otherwise using something like pipenv to not install all dependencies globally would probably be the most recommended option

Python2.7 no smb module. Cant locate

Running kali 2020, I am trying to run CVE-2007-2447 which is a python2.7 script, which says:
import smb
from smb.SMBConnection import SMBConnection
I saved the script to a file and ran it, but I get ImportError: No module named smb. In the script, it says install pysmb by running pip install --user pysmb.
I did this, but still the same error message.
I tried to locate pysmb and found these packages:
$ locate pysmb
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info/PKG-INFO
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info/top_level.txt
/usr/share/system-config-printer/pysmb.py
/usr/share/system-config-printer/__pycache__/pysmb.cpython-39.pyc
I have had a problem before where packages only install for python3 and I have to copy the folders to python2.7. I tried that for this without success.
When I googled module smb, it comes up with samba. I installed the samba package but still nothing. Does anyone know how I can get smb module to python2.7?
You need to install using the Python 2.7 pip. Use the following command:
pip2.7 install pysmb
Pip no longer supports Python 2.
pip documentation v21.0.1
You need to use python 2 pip to install the module, instead of installing it for python 3. See How to use pip with Python 3.x alongside Python 2.x
.
In my case, the problem was simple.
I named the python script file 'smb.py'. 'smb.py' and'pysmb' were in conflict.

"ImportError: no module named 'requests'" after installing with pip

I am getting ImportError : no module named 'requests'.
But I have installed the requests package using the command pip install requests.
On running the command pip freeze in the command prompt, the result is
requests==2.7.0
So why is this sort of error happening while running the python file?
Run in command prompt.
pip list
Check what version you have installed on your system if you have an old version.
Try to uninstall the package...
pip uninstall requests
Try after to install it:
pip install requests
You can also test if pip does not do the job.
easy_install requests
I had this error before when I was executing a python3 script, after this:
sudo pip3 install requests
the problem solved, If you are using python3, give a shot.
One possible reason is that you have multiple python executables in your environment, for example 2.6.x, 2.7.x or virtaulenv. You might install the package into one of them and run your script with another.
Type python in the prompt, and press the tab key to see what versions of Python in your environment.
In Windows it worked for me only after trying the following:
1. Open cmd inside the folder where "requests" is unpacked. (CTRL+SHIFT+right mouse click, choose the appropriate popup menu item)
2. (Here is the path to your pip3.exe)\pip3.exe install requests
Done
if it works when you do :
python
>>> import requests
then it might be a mismatch between a previous version of python on your computer and the one you are trying to use
in that case : check the location of your working python:
which python
And get sure it is matching the first line in your python code
#!<path_from_which_python_command>
Opening CMD in the location of the already installed request folder and running "pip install requests" worked for me. I am using two different versions of Python.
I think this works because requests is now installed outside my virtual environment. Haven't checked but just thought I'd write this in, in case anyone else is going crazy searching on Google.

Flask installation on windows vs Ubuntu

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.

Categories