Re: [Tutor] No module named uno in virtual environment
On 09/08/2018 08:35 PM, Mats Wichmann wrote: On September 8, 2018 5:46:46 PM MDT, Jim wrote: On 09/08/2018 05:26 PM, Mats Wichmann wrote: On 09/07/2018 03:10 PM, Jim wrote: Mint 18.1 System python3 3.5.2 Python3-uno is available to the system python3. How can I make it available to python 3.6.5 in a virtual environment I installed using venv? with your virtualenv activated, just install it. python -m pip install uno My bad, I did not explain what python3-uno does. It is a system package that lets python interact with libreoffice. The uno that pip installs is a html generator. I used apt to install python3-uno on my system. System python3 can use it and the python 3.5 in one of my virtual environments can use it. Python 3.6 in my other virtual environment cannot access it. So to re-phrase my question. Python3-uno is installed on my system what do I need to do to get python 3.6 in a virtual environment to use it? Maybe I am missing something obvious. With all the advice given to use virtual environments I would think that this problem has come up, but googling did not produce a solution. Regards, Jim python ok, awkward naming issue. try openoffice-python instead? Unfortunately it produces the same result, no module uno found. I think all of the packages on pipy need the uno module to be installed to function. When I installed python3-uno using apt it was installed at /usr/lib/python3/dist-packages/uno.py. I have python 3.5 installed in a virtual environment and it can load the uno module. I have python 3.6 installed in virtual environment and it cannot load the uno module. Ok, I think I have solved it. Looking at the site-packages folder in the 3.5 virtual environment shows uno.py and unohelper.py. In the 3.6 virtual environment they are missing. Simply putting a copy of them in the python3.6 site-packages folder allows me to import uno and run a program that depends on importing uno. I don't know if they should have been put there when I installed the 3.6 virtual environment or if I did something wrong when I installed it, but now it works. Mats, thanks for all your help. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] No module named uno in virtual environment
On 09/09/2018 10:49 AM, Jim wrote: >> ok, awkward naming issue. try openoffice-python instead? >> > > Unfortunately it produces the same result, no module uno found. I think > all of the packages on pipy need the uno module to be installed to > function. > > When I installed python3-uno using apt it was installed at > /usr/lib/python3/dist-packages/uno.py. I have python 3.5 installed in a > virtual environment and it can load the uno module. I have python 3.6 > installed in virtual environment and it cannot load the uno module. > > Ok, I think I have solved it. Looking at the site-packages folder in the > 3.5 virtual environment shows uno.py and unohelper.py. In the 3.6 > virtual environment they are missing. Simply putting a copy of them in > the python3.6 site-packages folder allows me to import uno and run a > program that depends on importing uno. > > I don't know if they should have been put there when I installed the 3.6 > virtual environment or if I did something wrong when I installed it, but > now it works. > > Mats, thanks for all your help. Glad it works, but you've left me curious now. On a Fedora system these two files come from libreoffice-pyuno: /usr/lib64/python3.6/site-packages/uno.py /usr/lib64/python3.6/site-packages/unohelper.py and I don't presently see any way they are going to make it into a virtualenv that is *not* set up to grab the system site-packages (that is, created with the --system-site-packages option), I'm not finding anything in PyPi that looks like it can provide this. The package I mentioned above certainly doesn't. uno.py imports the binary (shared object) pyuno module, which is fine, that one is located wherever the {open,libre}office install puts it - on my system just before the import it has done: sys.path.append('/usr/lib64/libreoffice/program') maybe your 3.5 virtualenv was created differently than your 3.6 one and that's why you have it there? meanwhile, this is looking to my untrained eye like a small hole. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] No module named uno in virtual environment
On 09/09/2018 01:29 PM, Mats Wichmann wrote: On 09/09/2018 10:49 AM, Jim wrote: ok, awkward naming issue. try openoffice-python instead? Unfortunately it produces the same result, no module uno found. I think all of the packages on pipy need the uno module to be installed to function. When I installed python3-uno using apt it was installed at /usr/lib/python3/dist-packages/uno.py. I have python 3.5 installed in a virtual environment and it can load the uno module. I have python 3.6 installed in virtual environment and it cannot load the uno module. Ok, I think I have solved it. Looking at the site-packages folder in the 3.5 virtual environment shows uno.py and unohelper.py. In the 3.6 virtual environment they are missing. Simply putting a copy of them in the python3.6 site-packages folder allows me to import uno and run a program that depends on importing uno. I don't know if they should have been put there when I installed the 3.6 virtual environment or if I did something wrong when I installed it, but now it works. Mats, thanks for all your help. Glad it works, but you've left me curious now. On a Fedora system these two files come from libreoffice-pyuno: /usr/lib64/python3.6/site-packages/uno.py /usr/lib64/python3.6/site-packages/unohelper.py and I don't presently see any way they are going to make it into a virtualenv that is *not* set up to grab the system site-packages (that is, created with the --system-site-packages option), I'm not finding anything in PyPi that looks like it can provide this. The package I mentioned above certainly doesn't. uno.py imports the binary (shared object) pyuno module, which is fine, that one is located wherever the {open,libre}office install puts it - on my system just before the import it has done: sys.path.append('/usr/lib64/libreoffice/program') maybe your 3.5 virtualenv was created differently than your 3.6 one and that's why you have it there? meanwhile, this is looking to my untrained eye like a small hole. I am puzzled also. My memory isn't what it used to be but I think I created them the same way. Looking at the config files I see. home = /usr/bin include-system-site-packages = false version = 3.5.2 and home = /usr/bin include-system-site-packages = false version = 3.6.3 I don't know if it makes a difference or not, but python3.5 is the system default python3 and python3.6 was installed from LP-PPA-jonathonf-python-3.6/now and LP_PPA-jonathonf-python-3.6/xenial. Maybe the install script malfunctioned or was lacking some step. I may email jonathon to see if he has any ideas. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] building package on mac os
I have a package that I am working on. I am using Pycharm. The directories are set up correctly. In my frameworks I have Python 2.7 Python 3.5 Python 3.6 Python 3.7 Current - which is Python 2.7 After navigating to the directory with the package I run the following in my terminal python3 setup.py sdist bdist_wheel This runs fine and it appears all is correct with no messages or warning. Then I go to the main user directory and pip install directory/packagename It appears the wheel installs in a private/var/ folder if I change the statement to python3.6 pip install directory/packagename I get an error 2 cannot find director. I need to change my current python to 3.6 and also figure out how to install the package. I have seen some instructions to edit the bash file but before I do this I would like to resolve the install issue Glenn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with building bytearray arrays
Cameron, et al. First off, thank you for being patient with me. I'm not used to the email list communication style. Since Cameron's response was the one that raised the most questions / comments, I'm going to reply to it. Inline.. now that I know that this is the preferred method... Before I jump in, the 1000 foot view is I have to send an array of 512 bytes down the SPI loop, and read back 512 bytes that were latched in from a control interface. Unfortunately, there's a glitch in the FTDI part and I can't just send the 512 bytes.. the part times out and and causes the script to terminate early... So, my solution was to 'chunk' the data into smaller groups which the part _can_ handle. This works fine until I come to the point where I concatenate the 'chunks' into my 512 byte array.. which other functions will then process. The libraries that I'm using are from the project link below. I'm learning from all of you how much code to post, I didn't want to post the entire library, but the way it's set up it is hard not to.. as has been pointed out.. methods of classes and then there's other files that contain some of the low-level workings.. https://github.com/adafruit/Adafruit_Python_GPIO Anyhow, on with the 'show'.. On Sat, Sep 8, 2018 at 6:49 AM, Cameron Simpson wrote: > On 08Sep2018 20:01, Cameron Simpson wrote: >>> >>> So, if I'm understanding the transfer() function correctly, the >>> function takes and returns a bytearray type. >> >> >> It would be good to see the specification for the transfer function. They >> we can adhere to its requirements. Can you supply a URL? > > > I see you supplied the whole transfer function in your first message :-( Yes, I realize now that I left out important information. I have my own transfer function which is the supplied transfer function with a bunch of GPIO wrapped around it, and the 'chunking'. This way I can call it when I need to send and receive data from the loop, which is often. In the end, I will have to talk with several different SPI devices, all of which will have to have different GPIO line wiggling going on before and after they call the spi.transfer. You're walk-through is very helpful. > > I'll recite it here and walk through its contents to explain: > >def transfer(self, data): > > Ok, this is a method, a particular type of function associated with a class > instance. (All objects are class instances, and the class is their type.) > > So to call this you would normally have a control object of some kind. [...] > Ah, it looks like you should have an SpiDev instance, inferring from this > code: > > > https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py > > So suppose you've got such an object and a variable referring to it, let's > say it is named "spi". You'd normally call the transfer function like this: > > spi.transfer(some_data) > > instead of calling transfer() "bare", as it were. Again, I was generalizing and also being somewhat lazy and not typing it all... my bad. > > When you call a Python method, the instance itself is implicitly passed as > the parameter "self" (well, the first parameter - in Python we always call > this "self" like C++ uses "this"). Ah, the one 'thorn' in my side is "this". I have considerable difficulty with the 'this' concept. That probably means that my code could be 'better', but I tend to avoid "this" like the plague. > >"""Full-duplex SPI read and write. The specified array of bytes will > be >clocked out the MOSI line, while simultaneously bytes will be read > from >the MISO line. Read bytes will be returned as a bytearray object. >""" > > This is a docstring. It is like a comment but it gets attached to the > function and can be inspected. Not your problem. > ># Build command to read and write SPI data. >command = 0x30 | (self.lsbfirst << 3) | (self.read_clock_ve << 2) | > self.write_clock_ve > > This constructs a value just as you would in C. > >logger.debug('SPI transfer with command {0:2X}.'.format(command)) > > Write a debugging message. I saw this, but I don't know how to turn it 'on' so I could see the log messages. I wouldn't mind doing this with my code as well. Perhaps creating my own log? Right now, I have a verbose flag that I pass to all my functions.. called disp. Then for each place where I want to see a value, etc, I have a line that reads: if(disp): print " What data is this ", data > ># Compute length low and high bytes. ># NOTE: Must actually send length minus one because the MPSSE engine ># considers 0 a length of 1 and a length of 65536 >length = len(data) >len_low = (length-1) & 0xFF >len_high = ((length-1) >> 8) & 0xFF > > All just like C. > ># Send command and length. >self._assert_cs() > > I would guess that this raises a control signal. Ah, RS-232? So > clear-to-send then. This is actually a chip sel
Re: [Tutor] Help with building bytearray arrays
On 09Sep2018 17:06, Chip Wachob wrote: Before I jump in, the 1000 foot view is I have to send an array of 512 bytes down the SPI loop, and read back 512 bytes that were latched in from a control interface. Unfortunately, there's a glitch in the FTDI part and I can't just send the 512 bytes.. the part times out and and causes the script to terminate early... So, my solution was to 'chunk' the data into smaller groups which the part _can_ handle. This works fine until I come to the point where I concatenate the 'chunks' into my 512 byte array.. which other functions will then process. Sounds good to me. The libraries that I'm using are from the project link below. I'm learning from all of you how much code to post, I didn't want to post the entire library, but the way it's set up it is hard not to.. as has been pointed out.. methods of classes and then there's other files that contain some of the low-level workings.. https://github.com/adafruit/Adafruit_Python_GPIO Thanks. Yes, I realize now that I left out important information. I have my own transfer function which is the supplied transfer function with a bunch of GPIO wrapped around it, and the 'chunking'. This way I can call it when I need to send and receive data from the loop, which is often. In the end, I will have to talk with several different SPI devices, all of which will have to have different GPIO line wiggling going on before and after they call the spi.transfer. [...] def transfer(self, data): Ok, this is a method, a particular type of function associated with a class instance. (All objects are class instances, and the class is their type.) So to call this you would normally have a control object of some kind. [...] Ah, it looks like you should have an SpiDev instance, inferring from this code: https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py So suppose you've got such an object and a variable referring to it, let's say it is named "spi". You'd normally call the transfer function like this: spi.transfer(some_data) [...] When you call a Python method, the instance itself is implicitly passed as the parameter "self" (well, the first parameter - in Python we always call this "self" like C++ uses "this"). Ah, the one 'thorn' in my side is "this". I have considerable difficulty with the 'this' concept. That probably means that my code could be 'better', but I tend to avoid "this" like the plague. It isn't as big a deal as you might imagine. An object method essentially gets the object as a piece of context. So a method call like this: spi.transfer(data) just has the "spi" object available within the method for use, for example is probably is already set up with all the hardware access you're going to make use of. So lower down in the function, when it goes: self._ft232h._write(str(bytearray(data))) all you're doing is making use of the already initialised _ft232h object to do the write, and that comes along with the "spi" object you called the transfer method through. So from your point of view it's just context for the transfer function. logger.debug('SPI transfer with command {0:2X}.'.format(command)) Write a debugging message. I saw this, but I don't know how to turn it 'on' so I could see the log messages. I wouldn't mind doing this with my code as well. Perhaps creating my own log? Right now, I have a verbose flag that I pass to all my functions.. called disp. Then for each place where I want to see a value, etc, I have a line that reads: if(disp): print " What data is this ", data Ah, logging. Yes, it is probably worth learning a little about, just to hook it it. You can at least get away from passing your "disp" variable around - just call the right logging call (warning, info, debug, error etc) and tune which messages get out from your main programme. The logging module is documented here: https://docs.python.org/2.7/library/logging.html#module-logging So your main programme would set up the logging, including a logging level. The module comes with five predefined levels from DEBUG through to CRITICAL. Then in your code you write messages like the debug one above. When you're debugging you might set the systems level to DEBUG and see heaps of messages, or INFO to see progress reporting, or WARNING to just see when things go wrong. Then your code just writes messages are a suitable level and the global setting controls which ones get out. All you really need to do is "import logging" and then just call "logging.warning" or "logging.debug" etc. There's a tutorial here: https://docs.python.org/2.7/howto/logging.html#logging-basic-tutorial Get off the ground like that and return to your main programme. The whole logging system can be rather complicated if you get sucked into learning it thoroughly. [...] # Send command and length. self._assert_cs() I would guess that this raises a control signal. Ah, R