Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 code does not execute. #23

Open
clplaneguy opened this issue Feb 8, 2019 · 8 comments
Open

Python 3 code does not execute. #23

clplaneguy opened this issue Feb 8, 2019 · 8 comments

Comments

@clplaneguy
Copy link

Python 3 checks the new PythonForMegaPi library for consistency with Python 3. The old code for Python 2 does not pass the test.

pi@raspberrypi:~ $ python3 MyRobot.py
Traceback (most recent call last):
File "MyRobot.py", line 2, in
from megapi import *
File "/usr/local/lib/python3.5/dist-packages/megapi.py", line 12
print self
^
SyntaxError: Missing parentheses in call to 'print'

@MrHezhisheng
Copy link
Collaborator

Please use the command " pip install megapi --upgrade" to update your megapi package.

@clplaneguy
Copy link
Author

sudo pip uninstall megapi // To uninstall 0.1.9
sudo pip install megapi // To install 0.2.0

pip install megapi --upgrade

pi@raspberrypi:~ $ pip install megapi --upgrade
Collecting megapi
Downloading https://files.pythonhosted.org/packages/a9/ff/4db9a95b8bcd8c14b6b2f4fe4e4b493c28f7401ea1251a44bda90a1f7d25/megapi-0.2.2.tar.gz
Building wheels for collected packages: megapi
Running setup.py bdist_wheel for megapi ... done
Stored in directory: /home/pi/.cache/pip/wheels/23/c4/87/b720ea61177e8ee371d0982261ceb5382f066c47c64c972f91
Successfully built megapi
Installing collected packages: megapi
Successfully installed megapi-0.2.2

pi@raspberrypi:~ $ python3 BigBot_New.py
Traceback (most recent call last):
File "BigBot_New.py", line 10, in
from megapi import *
File "/usr/local/lib/python3.5/dist-packages/megapi.py", line 12
print self
^
SyntaxError: Missing parentheses in call to 'print'
pi@raspberrypi:~ $

@clplaneguy
Copy link
Author

Version 0.2.2 is not getting to Python3.5!

pi@raspberrypi:/usr/local/lib/python3.5/dist-packages $ ls
init.py megapi-0.1.9.dist-info megapi.py pycache setup.py

pi@raspberrypi:/usr/local/lib/python3.5/dist-packages $ more megapi.py
import serial
import sys,time,math,random
import signal
from time import ctime,sleep
import glob,struct
from multiprocessing import Process,Manager,Array
import threading

class mSerial():
ser = None
def init(self):
print self

@clplaneguy
Copy link
Author

pi@raspberrypi:~ $ python3.7 BigBot_New.py
Traceback (most recent call last):
File "BigBot_New.py", line 1, in
import serial
ModuleNotFoundError: No module named 'serial'
pi@raspberrypi:~ $

@MrHezhisheng
Copy link
Collaborator

Please check your environment. The contents of megapi.py are:
`# -- coding: utf-8 -

import sys

if sys.version > '3':
PY3 = True
print("\r\nVersion:" + sys.version)
from megapi_python3 import *
else:
PY3 = False
print("\r\nVersion:" + sys.version)
from megapi_python2 import *`

@MrHezhisheng
Copy link
Collaborator

The way to solve this problem(No module named 'serial') is : pip install pyserial

@clplaneguy
Copy link
Author

Python2, Python3 and Python3.7 each have their own folder-(python2.7), (python3.5) and (python3.7) respectively. Python(2) in folder (python2.7) functions correctly and thus must be populated correctly. It also seems to conform to what I would expect with respect to PythonForMegaPi. The (python3.5) and (python3.7) folders do not seem to be populated with the correct PythonForMegaPi code. The (python3.5) folder refers to megapi 0.1.9 which is how it is getting to 'print self'. The (python3.7) folder does not even have a dist-packages folder.

The following are notes on what I have done and the responses that I got.

pi@raspberrypi:/usr/local/lib $ ls
libpython3.7m.a pkgconfig pypy2.7 python2.7 python3.5 python3.7

pi@raspberrypi:/usr/local/lib/python2.7/dist-packages $ ls
init.py megapi-0.2.0.dist-info megapi.py megapi_python2MAM.py megapi_python2.pyc megapi_python3.pyc serial setup.pyc
init.pyc megapi2.py megapi.pyc megapi_python2.py megapi_python3.py pyserial-2.7.egg-info setup.py

pi@raspberrypi:/usr/local/lib/python3.5/dist-packages $ ls
init.py megapi-0.1.9.dist-info megapi.py pycache setup.py

pi@raspberrypi:/usr/local/lib/python3.7 $ ls
abc.py code.py dbm getopt.py lib-dynload os.py _pydecimal.py smtpd.py sysconfig.py typing.py
aifc.py collections decimal.py getpass.py LICENSE.txt _osx_support.py pydoc_data smtplib.py tabnanny.py unittest
antigravity.py _collections_abc.py difflib.py gettext.py linecache.py pathlib.py pydoc.py sndhdr.py tarfile.py urllib
argparse.py colorsys.py dis.py glob.py locale.py pdb.py _pyio.py socket.py telnetlib.py uuid.py
ast.py _compat_pickle.py distutils gzip.py logging phello.foo.py queue.py socketserver.py tempfile.py uu.py
asynchat.py compileall.py doctest.py hashlib.py lzma.py pickle.py quopri.py sqlite3 test venv
asyncio _compression.py dummy_threading.py heapq.py macpath.py pickletools.py random.py sre_compile.py textwrap.py warnings.py
asyncore.py concurrent _dummy_thread.py hmac.py mailbox.py pipes.py reprlib.py sre_constants.py this.py wave.py
base64.py config-3.7m-arm-linux-gnueabihf email html mailcap.py pkgutil.py re.py sre_parse.py _threading_local.py weakref.py
bdb.py configparser.py encodings http _markupbase.py platform.py rlcompleter.py ssl.py threading.py _weakrefset.py
binhex.py contextlib.py ensurepip idlelib mimetypes.py plistlib.py runpy.py statistics.py timeit.py webbrowser.py
bisect.py contextvars.py enum.py imaplib.py modulefinder.py poplib.py sched.py stat.py tkinter wsgiref
_bootlocale.py copy.py filecmp.py imghdr.py multiprocessing posixpath.py secrets.py stringprep.py tokenize.py xdrlib.py
bz2.py copyreg.py fileinput.py importlib netrc.py pprint.py selectors.py string.py token.py xml
calendar.py cProfile.py fnmatch.py imp.py nntplib.py profile.py shelve.py _strptime.py traceback.py xmlrpc
cgi.py crypt.py formatter.py inspect.py ntpath.py pstats.py shlex.py struct.py tracemalloc.py zipapp.py
cgitb.py csv.py fractions.py io.py nturl2path.py pty.py shutil.py subprocess.py trace.py zipfile.py
chunk.py ctypes ftplib.py ipaddress.py numbers.py _py_abc.py signal.py sunau.py tty.py
cmd.py curses functools.py json opcode.py pycache _sitebuiltins.py symbol.py turtledemo
codecs.py dataclasses.py future.py keyword.py operator.py pyclbr.py site-packages symtable.py turtle.py
codeop.py datetime.py genericpath.py lib2to3 optparse.py py_compile.py site.py _sysconfigdata_m_linux_arm-linux-gnueabihf.py types.py

1920 pip
1921 python help
1922 python -m install pyserial
1923 python -m pip install pyserial
1924 python3 -m pip install pyserial
1925 python3.7 -m pip install pyserial
1926 python37 -m pip install pyserial

pi@raspberrypi:~ $ pip install pyserial
Collecting pyserial
Using cached https://files.pythonhosted.org/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl
Installing collected packages: pyserial
Successfully installed pyserial-3.4
pi@raspberrypi:~ $

pi@raspberrypi:~ $ python BigBot_New.py
Version:2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516]
sys.platform is: linux2
BigBot_New program running
2/18/2019
init MegaPi
<megapi_python2.mSerial instance at 0x76705aa8>
1)pack = bytearray([0xff,0x55,0x07,0x00,0x02,deviceId,0x02,slot]+Theirbot.short2bytes(speed))
^Z
[1]+ Stopped python BigBot_New.py

pi@raspberrypi:~ $ python3 BigBot_New.py
Traceback (most recent call last):
File "BigBot_New.py", line 10, in
from megapi import *
File "/usr/local/lib/python3.5/dist-packages/megapi.py", line 12
print self
^
SyntaxError: Missing parentheses in call to 'print'
pi@raspberrypi:~ $ python37 BigBot_New.py
bash: python37: command not found

pi@raspberrypi:~ $ python3.7 BigBot_New.py
Traceback (most recent call last):
File "BigBot_New.py", line 1, in
import serial
ModuleNotFoundError: No module named 'serial'

@MrHezhisheng
Copy link
Collaborator

Your environment looks pretty messy. Maybe you'll have to reinstall Python2 or Python3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants