Snowman
Snowman

Reputation: 21

Question about installing packages on Python 2.7

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

Upvotes: 0

Views: 1328

Answers (1)

Abhishek Jaisingh
Abhishek Jaisingh

Reputation: 1730

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.

Upvotes: 1

Related Questions