Python 3 Selenium NameError: name 'basestring' is not defined - python

A few weeks ago, I installed Selenium on a Linux Mint (an Ubuntu derivative) machine and developped a few Puthon scrapping scripts with it. Everyhting worked fine.
Now, I am trying to replicate the installation on another machine, also under Linux Mint, and I am stuck. This is what I get:
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> l_driver = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 62, in __init__
firefox_options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._get_firefox_start_cmd()
NameError: name 'basestring' is not defined
I installed Selenium exactly the same way as before:
sudo pip3 install -U Selenium
The installation seems ok and does not report any error. Previously, I had installed pip3 with the apt command:
sudo apt-get install python3-pip
Also no errors or problems. I installed a couple of other Python modules with pip3 and they all work.
None of my scripts will run. They all fail on the first line where I want to open a Firefox WebDriver. On my earlier machine however, everything still works fine and all my scripts run flawlessly as before.
What the heck is going on ? What am I missing ? Is this a Python 2 vs. 3 issue (the 'basestring' name points that way) ?

It's a bug in the latest version of selenium (2.53.0).

Related

Unable to import pyperclip in my python IDLE, but able to import from command prompt

This is my first question on stackoverflow and I'm new to Python.
I want to import pyperclip module.
So I went to cmd, ran as administrator, moved to the path using - cd \Program Files\Python37\Scripts and downloaded pip via pip3 install pyperclip command and it is successfully downloaded.
Now from IDLE I'm not able to import it
Following is the output from IDLE, it has not got that pyperclip module to import
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pyperclip
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
>>>
After this I did some research I found that, there could be possibility that it must have installed in some other directory. so from the research I found pyperclip folder and pyperclip-1.8.0-py3.6.egg-info folder in one of sub directory, which I copied and pasted in C:\Program Files\Python36 directory.
With above thing also I unable to import pyperclip from IDLE.
I went to command prompt, typed python and able to import it
Following is output
C:\Users\Administrator>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyperclip
>>>
So I'm not able to import from IDLE, but able to do in command prompt.
1 more problem I found as I'm new to python,
IDLE is showing python 3.8.2 and on command prompt it is showing 3.6. I have downloaded only 1 python and I have only 1 python installed. why there is this version difference 3.6 and 3.8.2
UPDATE:
With following command on IDLE, I able to import pyperclip. But it is only for current opened IDLE. After closing IDLE and reopening it, I have do these commands again. How to fix it for all time
>>> import sys
>>> sys.path.insert(1, 'C:/Program Files/Python36')
>>> import pyperclip
~~~~~~~~~~
SOLVED:
In your case, IDLE is using one Python interpreter (Python 3.8.2), while in the command-line you run another one (Python 3.6.0), with pyperclip installed. You'd be better off to do ONE of the following steps:
1) use multiple virtual environments to solve this problem easily (recommended). Read this article for more information.
2) install the required module on both Python interpreters, by running pip install pyperclip either (depending on the Python version) from C:\PythonXX\Scripts or C:\Program files\PythonXX\Scripts
3) you may also use single Python interpreter on your machine: remove one of the interpreters and then "Repair" another one (to fix the filetypes associations). To do this, open the installer from Windows uninstall manager and follow the steps it will give you.
I found 1 more python IDLE installed in directory
C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32
I copied pyperclip folder and pyperclip-1.8.0-py3.6.egg-info folder from C:\Program Files\Python36. And it solved my problem thank you guys
I had the same issue but realized this later...what I figured out was that pip was installing the module into the site-packages folder in the AppData\Roaming location instead of the AppData\Local folder. Once I moved the module's folders into the right spot it worked!
If you also run into this issue, maybe just do a quick check that pip is installing where you want it to. Now to figure out how to change the default install path...

Python 2 Bindings Net-SNMP Error - undefined symbol: netsnmp-memdup

I successfully compiled net-snmp-5.7.3 on Ubuntu. :D This is the specific version of Ubuntu:
Linux loserBox 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
I seemed to have successfully installed the Python bindings for net-snmp too. This is included with the net-nsmp download as a different folder titled 'Python' with the setup.py file in it. However when running the command python setup.py test I noticed some problems. I thought this may be nothing to worry about so I went ahead and executed python setup.py install I was not sure what the instructions meant in the README file that say, "python setup.py test (requires a locally running agent w/ config provided)". So, this is why I installed it with the failed test or something. Anyways, I am not sure if this is a problem or not.
After successfully installing the python bindings for net-snmp I switched directories back to my Desktop and opened up an interactive python shell. From here I imported the netsnmp module and received the below error. It almost looks like there is a spelling error in the variable netsnmp_memdup that is throwing the error in the Traceback. This looks like a problem with the C code and not 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 netsnmp
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning:
/home/loser_user/.python-eggs is writable by group/others and vulnerable to attack
when used with get_resource_filename. Consider a more secure location
(set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/__init__.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 6, in __bootstrap__
ImportError: /home/loser_user/.python-eggs/netsnmp_python-1.0a1-py2.7-linux-x86_64.egg-
tmp/netsnmp/client_intf.so: undefined symbol: netsnmp_memdup
Does anyone know how to fix this problem? I looked on the mailing list page on sourceforge for this project and searched the supoort archives but did not find anything.
Thanks for listening to a crazy man's Python problems.
Happy Holidays,
user_loser
Alrgihty, thanks to my good friend Naveen, we have traced this down to an actual bug in the Python Net-SNMP bindings in the 5.7.3.
There are two ways around this:
Use the Python bindings in Net-SNMP 5.7.2
See this commit on our fork of the Net-SNMP Python library (only started yesterday so bear with us): https://github.com/fgimian/easysnmp/commit/fa86af977b563f65e7d70243752d48b94a8d5686 and replicate this in your download of Net-SNMP.

Ubuntu 12.04 How To Run Python 3.3.2 Program In Terminal

OK so for school I am having to set up a computer using Ubuntu 12.04 to run Python programs written in Python 3.3. I was aware that 12.04 came with Python 3.2, so I followed the procedure in the first reply in this thread to install Python 3.3:
Now when I open the Terminal, I type ~/bin/py to get it to display the following at the top of the terminal:
Python 3.3.2 (default, Dec 10 2013, 11:35:01)
[GCC 4.6.3] on Linux
Type "help", "copyright", "credits", or "license" for more information.
>>>
So far so good. Now I am having trouble replicating the functionality of the same Python program that I execute as follows on my Windows laptop.
(This is what I type in the Python commandline on windows)
import filereader
from filereader import *
reader = filereader("C:\Python33\ab1copy.ab1")
reader.show_entries()
The end result is a directory of data types found in the file. The filereader class is located in Python33\Lib\site-packages\filereader.py in the above example. On the Ubuntu computer its location is Python-3.3.2\Lib\site-packages\filereader.py. Also on Ubuntu, the ab1copy.ab1 file is located in the home directory for now.
After I achieve the recognition of Python 3.3.2 in the Ubuntu Terminal as noted above, how can I replicate my program's functionality there? If I try to put in the same first command "import filereader" I get the following error:
>>>import filereader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'filereader'
try this in the terminal
python3 your_file.py
It's probably not in your python path.
Check this to see where it looks for your source:
import sys
print(sys.path)

How can I make my default python homebrew?

I've recently given up on macports and gone to homebrew. I'm trying to be able to import numpy and scipy. I seem to have installed everything correctly, but when I type python in terminal, it seems to run the default mac python.
I'm on OSX 10.8.4
I followed this post: python homebrew by default
and tried to move the homebrew directory to the front of my %PATH by entering
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
then "echo $PATH" returns
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
however when I look for where my python is by "which python", I get
/usr/bin/python
For some reason when I import numpy in interpreter it works but not so for scipy.
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy
>>>
What do I need to do to get python to run as my homebrew-installed python? Should this fix my problem and allow me to import scipy?
Homebrew puts things in a /usr/local/Cellar/<appname> directory, if I'm not mistaken. You should find the bin of the python in there and put it in your path before hitting /usr/bin.
For example, on my 10.8, python is located at /usr/local/Cellar/python/2.7.5/bin and I put that directory before /usr/bin/python in my PATH variable.
I do that similarly for other instances of me wanting to use homebrew version of an app, another example being sqlite.

Local Appengine stopped working

I tried to run one of my AppEnigne projects (python) today but it will no longer launch, this is the stack trace I'm getting.
*** Running dev_appserver with the following flags:
--admin_console_server= --port=8080 --clear_datastore
Python command: /usr/bin/python2.5
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 77, in <module>
run_file(__file__, globals())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 73, in run_file
execfile(script_path, globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_main.py", line 138, in <module>
import logging
ImportError: No module named logging
I thought it could be a python 2.6 error but I adjusted my path to /usr/bin/python2.5 and its still not working. I'm running OSX 10.6.8 and have the latest AppEngineLauncher 1.5.4
The only thing I changed recently that might have affected this is when I updated my XCode to the latest version, v4.2 build 4C199
Has anyone else faced this issue recently?
EDIT
I can't import logging from the terminal either, same message. Here's Python's path.
Chriss-MacBook-Pro:bin chris$ /usr/bin/python2.5
Python 2.5.4 (r254:67916, Aug 2 2010, 20:09:39)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload',
'/Library/Python/2.5/site-packages',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-unicode']
>>>
Thanks to Nick and Wobble I've figured it out. I recently updated my XCode install to the 4.2 GM release and removed the beta versions. Along the way OSX forgot where gcc was installed and prevented it from compiling the python modules like logging. This resulted in missing .pyo files inside /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25/logging which prevents import logging from working.
Logging wasn't the only module that wasn't compiled, just the first one AppEngine tried to import.
Solution: uninstall and do a clean install of XCode. Make sure gcc can be found on your PATH and everything should be fine.

Categories

Resources