Mar-09-2019, 05:36 AM
My abrupt answer in _no_, because pip2 installation interfers (as far as I know) with pip of Py3, but I'm confident in forum's drifts to overcome the problem.
The main Python installation in my pc, Win-10 equipped, is as follows:
Thx in advance, and cheers
The main Python installation in my pc, Win-10 equipped, is as follows:
Output:C:\Users\Alfabeta>python -V
Python 3.7.2
C:\Users\Alfabeta>pip -V
pip 19.0.3 from c:\users\alfabeta\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)
C:\Users\Alfabeta>pip list
Package Version
-------------- --------
2to3 1.0 <---- converter py2/py3, I won't use it!
altgraph 0.16.1
astropy 3.1.2
de421 2008.1
future 0.17.1
jplephem 2.9
julian 0.14
macholib 1.11
mpmath 1.1.0
numpy 1.16.2
pefile 2018.8.8
pip 19.0.3
PyInstaller 3.4
pywin32-ctypes 0.2.0
setuptools 40.6.2
sympy 1.3
I reach the Py2 version by means of this batch file:Output:@echo off
cls
cd\0_BackUP-29-Feb-2016\Temp\Python26
python2 -V
python2 --help
python2 my-newton.py
pause
So, the python release name is shown below and runs properly next script# --------- my-newton.py ------------------ # -- (derivative computed through finite interval dx=h) ---- def derivative(f, x, h): return (f(x+h) - f(x-h)) / (2.0*h) # via finite interval h def funzione(x): return x**3 - x -1 # Given function def solve(f, x0, h): lastX = x0 nextX = lastX + 10* h # different than lastX so loop starts OK while (abs(lastX - nextX) > h): newY = f(nextX) print "f(", nextX, ") = ", newY # printout progress lastX = nextX nextX = lastX - newY / derivative(f, lastX, h) # update estimate using Newton method return nextX xFound = solve(funzione, 2, 10**(-7)) # call the solver given starting value, tolerance print "solution: x = ", xFound # print the result # ------------------------------------------------------
Output:Python 2.6.5
usage: python2 [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
...........
...........
Running my-newton.py
-------------
f( 2.000001 ) = 5.00001100001
f( 1.54545504037 ) = 1.14575812265
f( 1.35961505435 ) = 0.153705563753
f( 1.32580135343 ) = 0.00462495304571
f( 1.32471904943 ) = 4.65779447723e-06
f( 1.32471795725 ) = 4.74331685041e-12
solution: x = 1.32471795724
Unfortunately, such a 'particular' installation allows a strong limitative use of Py2, due to the absence of libraries, commonly coming from (pip).Thx in advance, and cheers