Problem in a python2 file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem in a python2 file (/thread-12062.html) Pages:
1
2
|
Problem in a python2 file - sylas - Aug-07-2018 Hi all ! Because I installed "click" being in python2, I can import "click" only on python2. I cannot use 3.6 for this file. My problem appears at line 19. import click import math print("solver.py in python2.7") class Solver: def demo(self): print("Resolve second degree equation. Enter the coefficients(numbers): a,b,c") text = raw_input(' Are you ready: y/n ? ') print('you entered: ', text) text = "y" while (text == 'y'): # while True: a = float(input("a ")) b = float(input("b ")) c = float(input("c ")) d = b ** 2 - 4 * a * c if d >= 0: disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) print(root1, root2) else: print('This equation has no roots') print('do you want to begin again for another equation ? ') #text = raw_input(' y/n ? ') #print("you entered: ", text) click.echo('Do you agree ? y/n ', nl=False) text= click.getchar() click.echo() if text == b'y': click.echo('We wiil continue') elif text == b'n': click.echo('Abort!') exit() else: click.echo('Invalid input ! ') exit() Solver().demo() RE: Problem in a python2 file - Larz60+ - Aug-07-2018 click is available for python 3 make sure your pip is for python 3: pip -Vyou should see something to similar to: important thing is that version is python 3+if not use pip3 pip install click # or if necessary pip3 install click RE: Problem in a python2 file - wavic - Aug-07-2018 Python 3 comes with pip since 3.4. python3 -m pip install click will also work. Just to be sure that python3 pip will be used.
RE: Problem in a python2 file - sylas - Aug-07-2018 import click import math print("solver.py in python2.7") class Solver: def demo(self): print("Resolve second degree equation. Enter the coefficients(numbers): a,b,c") text = raw_input(' Are you ready: y/n ? ') print('you entered: ', text) text = "y" while (text == 'y'): # while True: a = float(input("a ")) b = float(input("b ")) c = float(input("c ")) d = b ** 2 - 4 * a * c if d >= 0: disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) print(root1, root2) else: print('This equation has no roots') print('do you want to begin again for another equation ? ') #text = raw_input(' y/n ? ') #print("you entered: ", text) click.echo('Do you agree ? y/n ', nl=False) text= click.getchar() click.echo() if text == b'y': click.echo('We wiil continue') elif text == b'n': click.echo('Abort!') exit() else: click.echo('Invalid input ! ') exit() sylvain@sylvain-HP-Laptop-15-bw0xx:~$ python solver.py File "solver.py", line 29 click.echo'Do you agree ? y/n ' ^ IndentationError: unexpected indent sylvain@sylvain-HP-Laptop-15-bw0xx:~$ pip -V pip 18.0 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7) I am on Linux. All my problems should disappear if I could easily make python3 the default language. RE: Problem in a python2 file - Gribouillis - Aug-07-2018 (Aug-07-2018, 10:08 AM)sylas Wrote: All my problems should disappear if I could easily make python3 the default language.This is not true, making python 3 the default language would not solve any problem. You can use python 3 and the click module without python 3 being the OS' default python. Trying to change the default python is a very bad idea. Don't do that. RE: Problem in a python2 file - sylas - Aug-07-2018 @wavic sylvain@sylvain-HP-Laptop-15-bw0xx:~$ python3 -m pip install click Requirement already satisfied: click in /usr/lib/python3/dist-packages (0.4.46+17.10.20170607.3.0ubuntu1) launchpadlib 1.10.5 requires testresources, which is not installed. You are using pip version 10.0.1, however version 18.0 is available. You should consider upgrading via the 'pip install --upgrade pip' command. @Larz click works well on python 2.7 #python2 import click click.echo('Do you agree ? [y/n] ', nl=False) c = click.getchar() click.echo() if c == b'y': click.echo('We will go on') elif c == b'n': click.echo('Abort!') exit() else: click.echo('Invalid input ! ') exit() print("sylas") RE: Problem in a python2 file - Gribouillis - Aug-07-2018 What is the output of python3 -c "import click; print(click)" ?
RE: Problem in a python2 file - sylas - Aug-07-2018 sylvain@sylvain-HP-Laptop-15-bw0xx:~$ python3 -c "import click; print(click)" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'click' RE: Problem in a python2 file - snippsat - Aug-07-2018 (Aug-07-2018, 10:08 AM)sylas Wrote: All my problems should disappear if I could easily make python3 the default language.You use python3 and pip3 with default setup that Ubuntu has.I did show you pipenv in an other post. This has been up several with you and as usual you struggle with all you do This mean that you use python3 my_script.py to run code with Python 3.pip3 install some_package to install to Python 3.Linux Python 3 environment Should use decorator with Click eg @click.command() .Basic Concepts. RE: Problem in a python2 file - sylas - Aug-08-2018 Please forget all things about pips and different python languages. Consider that the little file concerning pick, works very well on python2. Same thing for the solver equation file. The problem arrises when I try to join these 2 files. The interpreter tells that there is an indentation error, but I am sure he tells false. Can someone help to finish this job ? Thanks in advance. |