[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Parallella Community • View topic - Problems Importing Python Modules

Problems Importing Python Modules

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

Problems Importing Python Modules

Postby GlasierXplor » Mon Sep 04, 2017 3:12 am

GlasierXplor
 
Posts: 14
Joined: Thu Mar 09, 2017 8:46 am

Re: Problems Importing Python Modules

Postby mgentry10 » Sat Sep 09, 2017 6:20 pm

make sure to put the file extension on the end of the command. For example: epython yourFilename.py, without the quotes.
mgentry10
 
Posts: 4
Joined: Sun Jun 11, 2017 3:46 am

Re: Problems Importing Python Modules

Postby polas » Mon Sep 11, 2017 2:01 am

Hi - thanks for your interest in ePython. Yes the first way (without sudo) is the way to launch ePython.

So the question I have is where/what is the socket.py file, are you importing this in your Python code? I might be wrong, but I guess you are wanting to use the Python socket.py inbuilt module that wraps _socket. Unfortunately that is not possible - ePython implements just a subset of Python features and comes with a (very) limited number of specialist modules.

Two options here - 1) What are you wanting to use socket for? Would the message passing communications calls in parallel.py work instead? (To pass messages between cores.)
2) On the dev branch there is additional work on offloading codes from Python running on the host by decorating functions, using ePython as the execution engine (typically for kernels.)

Nick
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm

Re: Problems Importing Python Modules

Postby GlasierXplor » Mon Sep 11, 2017 4:32 am

Hi, thank you so much for replying.

I was importing socket.py as an example in the code I tested. I have a more complete set of code that needs to import other modules such as os.py and sys.py.

After copying the directory of /use/lib/python2.7/modules to /usr/include/epython/modules (some modules imported without a problem), modules like os.py has troubles being interpreted (a random 'import' in the commented section confused the epython interpreter). On the other hand, modules like sys.py cannot be found.

As a result, my code is not able to run.
GlasierXplor
 
Posts: 14
Joined: Thu Mar 09, 2017 8:46 am

Re: Problems Importing Python Modules

Postby polas » Mon Sep 11, 2017 9:52 am

Yes, it won't I am afraid - this isn't a full implementation of Python (to fit in the memory limits & there are certain things such as IO that the Epiphany can not do.) So standard Python modules won't work (for instance there isn't an OS running, so sys or os modules would be largely unsupportable without a large software stack underneath which we don't have the memory to support.)

As I say, there are two ways around this - either rewrite what you want using the modules provided by ePython (if these are sufficient), or on the dev branch there is offload support, where you write normal Python code but import the epython module. Then run this through any Python interpreter on the host (such as CPython) and any functions you decorate will execute on the Epiphany cores. Data transfer (arguments into the functions and return values) are handled transparently, so you can use the Epiphany for computation type stuff and then use Python modules such as os, socket and sys on the host to do what you want with these values.

I am happy to help further if you are struggling with specific code snippets etc that you are trying to do.

Cheers,
Nick
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm

Re: Problems Importing Python Modules

Postby GlasierXplor » Mon Sep 18, 2017 3:03 am

I am interested in the second method you have mentioned (importing ePython as a module).

Am I right to say that I can put epython.py (under mesham/epython/modules/fullpython) into the Python Modules path and import it as a module?

That being said, I cannot seem to find any references to the ePython modules. Am I also right to say that the provided ePython modules (mesham/epython/modules/*) also has to be copied into the Python Modules path and therefore imported as modules as well?
GlasierXplor
 
Posts: 14
Joined: Thu Mar 09, 2017 8:46 am

Re: Problems Importing Python Modules

Postby polas » Wed Sep 20, 2017 8:35 am

Hi - yes, import the epython module from mesham/epython/modules/fullpython and that should do you. This hasn't yet reached full maturity, what you will probably want to do is comment out line 501 (I think) which is thread.start_new_thread(pollScheduler,()) - this starts the scheduler in a thread but the nature of the Python interpreter means that it can eat quite a few resources. I will fix this when I get a chance.

No, not the mesham/epython/modules - and this is a bit confusing I guess.... the modules in mesham/epython/modules are for ePython running on the Epiphany. Basically these implement functionality which you can import into your code running on the Epiphany and it means we don't need to put that stuff in the interpreter/runtime (thus keeping it small.) If you look at these quite a few of them end up calling into the ePython runtime library. I think of these as "system" level modules (if that makes sense.)

The ePython module in mesham/epython/modules/fullpython is entirely different and implements the interface between the host Python code and the Epiphany. I am rethinking the directory structure of ePython, so will probably tweak the modules directory at some point to make this clearer.

Cheers,
Nick
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm


Return to Programming Q & A

Who is online

Users browsing this forum: Google [Bot] and 9 guests

cron