I am new to python and I am really confused about lot of things. I am developing my project mainly in PHP but as my host is unable to provide me access to v8js I have to use python to accomplish my tasks.
What I don't understand is:
On my server is running python 2.7, and If I use pip to install latest version of some package, will it install version that will work with python 2.7 or it will install it even if it is meant to run only in python 3?
I am trying to install and use https://pypi.org/project/cfscrape/ but I can't force it to work, but when try it on Repl.it it is working without any problem.
So I guess that something is not right on my server but don't know what, as I just used pip install cfscrape and it intalled that package.
Edit:
Do you think that this error could be result of using python 2 or this is not related to python version in use? All depadances are intalled
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 151, in _run_module_as_main
mod_name, loader, code, fname = _get_module_details(mod_name)
File "/usr/lib64/python2.7/runpy.py", line 101, in _get_module_details
loader = get_loader(mod_name)
File "/usr/lib64/python2.7/pkgutil.py", line 464, in get_loader
return find_loader(fullname)
File "/usr/lib64/python2.7/pkgutil.py", line 474, in find_loader
for importer in iter_importers(fullname):
File "/usr/lib64/python2.7/pkgutil.py", line 430, in iter_importers
import(pkg)
File "main.py", line 3, in
test = scraper.get("https://www.klix.ba/koronavirus-u-bih").content
File "/home/admin/.local/lib/python2.7/site-packages/requests/sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "/home/admin/.local/lib/python2.7/site-packages/cfscrape/init.py", line 129, in request
resp = self.solve_cf_challenge(resp, **kwargs)
File "/home/admin/.local/lib/python2.7/site-packages/cfscrape/init.py", line 204, in solve_cf_challenge
answer, delay = self.solve_challenge(body, domain)
File "/home/admin/.local/lib/python2.7/site-packages/cfscrape/init.py", line 292, in solve_challenge
% BUG_REPORT
ValueError: Unable to identify Cloudflare IUAM Javascript on website. Cloudflare may have changed their technique, or there may be a bug in the script.
On Repl.it it is working and on my server it is not
Most Python developers install more than one version of Python. This may be either due to the fact that the OS includes an old Python distribution or the developer himself/herself works on projects having different Python versions.
Running the pip executable directly with more than one Python distribution on a system is unpredictable and ambiguous. You can get some insight into what pip is actually executing using which command in Linux:
❯❯❯ which pip
/home/abhishek/software/miniconda2/envs/quantum/bin/pip
❯❯❯ which pip2
/home/abhishek/.local/bin/pip2
❯❯❯ which pip3
/home/abhishek/software/miniconda2/envs/quantum/bin/pip3
A better way to use pip is to explicitly specify the Python executable you want to use. This will make sure pip will use the python version you specified
❯❯❯ python -m pip # will use whatever python version this alias points to
❯❯❯ python2 -m pip
❯❯❯ python3 -m pip
PS: Python 2 is already depreciated. It is strongly recommended to use Python 3 for all use-cases.
Related
Trying to use the google api client, I have gotten an error that MANY others have gotten:
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlencode'
I have tried every solution found in StackOverflow, GitHub, and other places, including:
1) from this thread, changing the path in the actual code:
import sys
sys.path.insert(1, '/Library/Python/2.7/site-packages')
2) from this thread, changing the python path in the .bashrc and .bash_profile files:
pip show six | grep "Location:" | cut -d " " -f2
export PYTHONPATH=$PYTHONPATH:<pip_install_path>
source ~/.bashrc
3) and from this thread, downgrading my google api client to 1.3.2 (or at least trying to).
I'm new to programming so this could be a basic problem but I've spent days trying to troubleshoot and to no avail. It seems like no matter what I do, the old 1.4 version of six is being used. Any help you could provide would be MUCH appreciated!
EDIT: Full Traceback:
Traceback (most recent call last):
File "/Users/zachgoldfine/PycharmProjects/FirstTry/GetAroundRentalSpreadsheetRead.py", line 71, in <module>
spreadsheetId=spreadsheetId, range=rangeName1).execute()
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 129, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/googleapiclient/http.py", line 836, in execute
method=str(self.method), body=self.body, headers=self.headers)
File "/Library/Python/2.7/site-packages/googleapiclient/http.py", line 162, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/transport.py", line 186, in new_request
credentials._refresh(orig_request_method)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 761, in _refresh
self._do_refresh_request(http)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 774, in _do_refresh_request
body = self._generate_refresh_request_body()
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 716, in _generate_refresh_request_body
body = urllib.parse.urlencode({
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlencode'
Assuming it's indeed a problem with the six version, here is one way to install six and be able to use the newly installed version.
Important note: this will only work from your user account; not from any other account.
On the safe side: this will not alter the system Python environment, that is, system scripts that may use Python will continue to use the older pip version.
Firstly, reverse the three steps above. In particular, manually altering sys.path in a script should really very rarely be necessary.
Then, use the --user option, which installs a local version, that Python (when run by that user) will automatically pick up first.
To make sure the Python executable you are using corresponds to the pip module and (later) the installed six module, use the following:
python -m pip install six --user
where python may be something slightly else, if you happen to not use the system Python (e.g., z/usr/local/bin/python, orpython3, etc).
There is no need forsudo` or similar.
If pip complains that the requirement is already up to date (it shouldn't, or you wouldn't have gotten the above problems), try:
python -m pip install six --user --upgrade --force
Once done, you can check $HOME/Library/Python/x.y/lib/python/site-packages to see if you see the correct version of six there. This is your local user Library directory, not the system one. x.y is probably 2.7, but do check that python is actually that version.
The problem may also be with the google api client. I don't know if that has a pip installation, but otherwise you could try something similar as for six:
python -m pip install <google-api-client> --user (--upgrade --force)
I'm trying to run a Python script that involves ARP sniffing and is apparently dependent on the Scapy library being present. I have absolutely no idea what I'm doing but I'm reasonably good at Googling, following directions, and copying/pasting. I have it up and running on my Mac, but I'm stuck on what I hope is the last hurdle in getting Scapy working on my Windows computer (which is ultimately the one that needs to be running this script).
I followed all of the instructions at http://www.secdev.org/projects/scapy/doc/installation.html#windows, except that I chose Python 2.7 and used the newer 2.7-compatible versions of everything listed there. I used “python setup.py install” (successfully, as best I could tell) on all installs except Pypcap and Libdnet, which I installed via the Exe as an Administrator as instructed.
Unfortunately, when I type "scapy" into the command prompt to test if it works, I get the following information & error message:
C:\scapy-2.3.1>scapy
INFO: Can't import python gnuplot wrapper . Won't be able to plot.
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
Traceback (most recent call last):
File "C:\Python27\Scripts\\scapy", line 25, in <module>
interact()
File "C:\Python27\lib\site-packages\scapy\main.py", line 278, in interact
scapy_builtins = __import__("all",globals(),locals(),".").__dict__
File "C:\Python27\lib\site-packages\scapy\all.py", line 16, in <module>
from arch import *
File "C:\Python27\lib\site-packages\scapy\arch\__init__.py", line 79, in <module>
from windows import *
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 214, in <module>
ifaces.load_from_dnet()
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 173, in load_from_dnet
self.data[i["name"]] = NetworkInterface(i)
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 93, in __init__
self.update(dnetdict)
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 107, in update
self._update_pcapdata()
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 118, in _update_pcapdata
win_name = pcapdnet.pcap.ex_name(guess)
AttributeError: 'module' object has no attribute 'ex_name'
Can anyone help me out? If you need more information please let me know.
I am running Windows 10.
Thanks in advance,
- Ethan
I had same problem.
To solve it, i downloaded dnet-1.12.win32-py2.7.exe
and pcap-1.1.win32-py2.7.exe.
You might want to try with Scapy's current development version (from the Github repository). Support for Windows has been updated recently and should work without the need of Libdnet.
If that's not the case, you should probably open an issue.
Try it with scapy3k. Install python3 (e.g. I use Anaconda 3.5), and WinPcap driver. You do not need dnet or pypcap. Install using pip install scapy-python3 or from http://github.com/phaethon/scapy
I am trying to install a fresh version of virtualenv (there is some problem with the path that python has stored in sys.executable) and it turns out there is another problem that actually seems related.
When I try to run pip install virtualenv, I get this output:
-bash: /usr/local/Cellar/python/2.7.10_2/bin/pip: /usr/local/opt/python3/bin/python3.4:
bad interpreter: No such file or directory
Now my original point in reinstalling virtualenv is that I keep getting this error when I run virtualenv venv
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv.py", line 2363, in <module>
main()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 832, in main
symlink=options.symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 994, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1288, in install_python
shutil.copyfile(executable, py_executable)
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shutil.py", line 108, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/opt/python3/bin/python3.4'
As a sidenote that may be relevant, rather than using the default installed python3, I brew-installed a python3 with a brewed openssl (an application required it) and placed the path of the brewed python3 at the top of my /etc/paths.
I have tried to install and uninstall python multiple times without any success and am completely at a loss of what the problem could be. Any direction would be greatly appreciated.
EDIT
After #cel 's suggestions, it turned out that the head of my pip file (located at /usr/local/Cellar/python/2.7.10_2/bin/pip) was set to hardcode a python version as so #!/usr/local/opt/python3/bin/python3.4. I changed this to the output of which python which was /usr/local/Cellar/python/2.7.10_2/bin/python
This allowed me to succesfully create a virtualenv once again. Thanks!
I came across a similar problem when I used HomeBrew to upgrade my python from version 3.5.2 to version 3.6.0. HomeBrew updated the symlink /usr/local/bin/pip3 to /usr/local/Cellar/python3/3.6.0/bin/pip3 but my /usr/local/bin/pip was still using the old script and it was pointing to the python interpreter at /usr/local/opt/python3/bin/python3.5.
My course of action was as follows:
Unlinked /usr/local/bin/pip and updated it to point /usr/local/Cellar/python3/3.6.0/bin/pip3.
Created a new symlink /usr/local/bin/pip3.5 that pointed to /usr/local/Cellar/python3/3.5.2/bin/pip3 and updated the header of pip3.5 script to point to the python interpreter at /usr/local/Cellar/python3/3.5.2/bin/python3.5
Followed the same procedure for virtualenv.
P.S. Initially I didn't face this problem with virtualenv since I was using it with the -p option.
I am testing scrapy for the first time, and after installing it with the command:
sudo easy_install -U scrapy
everything seems to run ok. However, when I run:
scrapy startproject tutorial
I get the following:
luismacbookpro:~ luis$ scrapy startproject tutorial
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/Current/bin/scrapy", line 4, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pkg_resources.py", line 2711, in <module>
working_set.require(__requires__)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pkg_resources.py", line 690, in require
needed = self.resolve(parse_requirements(requirements))
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pkg_resources.py", line 588, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: lxml
Any idea about what's going on? As you can tell, I am not proficient at all with OSX, and I am still trying to move from a windows "mentality" to OSX, so I don't know where to add paths, modify settings, dependencies, etc. Not even sure how to perform a clean uninstall and start all over.
Any feedback is appreciated, even your suggestions to use alternative python libraries that can perform the same functionality of scrapy. Thanks!
I think this will solve the error message you're seeing:
sudo easy_install --upgrade lxml
This problem can arise on Macs when you use pip to install some packages and easy_install to install others.
Let us know how you go :)
I used easy_install to install pip, pip to install django, virtualenv, and virtualenvwrapper.
I have just returned to it a few weeks later and django does not seem to work anymore, but more concerning is I can't start the process over again as easy_install is returning the following error:
Traceback (most recent call last):
File "/usr/bin/easy_install-2.7", line 10, in <module>
load_entry_point('setuptools==0.6c12dev-r88846', 'console_scripts', 'easy_install')()
File "/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point
File "/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2220, in load_entry_point
ImportError: Entry point ('console_scripts', 'easy_install') not found
After a good evening of hunting I am stumped as to how to resolve this.
You seem to have a version conflict; note the setuptools-0.6c11-py2.7.egg path, but the /usr/bin/easy_install-2.7 script wants to load 0.6c12dev-r88846 instead.
The latter is a development version; it has the revision number of a subversion repository embedded in the version (dev-r88846).
I suspect you have two python installations; one is the system version (in /System/Library and the other is installed with the python installer into /Library/, and the stub script in /usr/bin/ may be installed with the system python.
If so, there'll be another copy of the stub at /Library/Python/2.7/bin/easy_install-2.7, which should work correctly.
I had the same issue, eventually ended up running the 2.7.3 easy_install by
/opt/python2.7.3/bin/easy_install which worked fine