« first day (3510 days earlier)      last day (1435 days later) » 
01:00 - 17:0017:00 - 00:00

1:49 AM
cbg
Found out about Python Dash today...it's like discovering cheesecake for the first time
 
`song = AudioSegment.from_mp3(data.selected_song["PATH"])
playing_song = pydub.playback._play_with_simpleaudio(song)`
I am searching to get the current_time
From github: Currently Undocumented:

Playback (pydub.playback)
Available methods: ['NamedTemporaryFile', '_play_with_ffplay', '_play_with_pyaudio', '_play_with_simpleaudio', 'get_player_name', 'make_chunks', 'play']
That's code works fine:

song = AudioSegment.from_mp3(data.selected_song["PATH"])
slices = song[::1000]
for slice in slices:
pydub.playback._play_with_simpleaudio(slice)
time.sleep(1)
 
wim
2:42 AM
@Aran-Fey NotImplemented
 
2:57 AM
Julia is overtaking python in the data science world is that true?
 
3:44 AM
I just came to know about suppress, is it better than try-except block?
 
wim
no
just another way of doing the same thing
 
4:06 AM
@Darkknight no, I don't think that's true; what indicators of this are you seeing?
 
4:21 AM
Folks, for print()ing with customizable indent level, do you use pprint, textwrap or what? Looking for something that's ok with long lines, Unicode-safe etc.
^ one nice-to-have requirement is something that works nicely with pandas commands like df.info() that directly write output, without needing print().
 
5:08 AM
https://regex101.com/r/igjCuo/134

can someone help me with this. i dont want unix word in the output. i believe this is due to to \s* i thought it was for white spaces
 
@SaiAstro what do you mean? \s* skips whitespace but then you have [^\s]* (which could more succinctly be written \S*) which matches non-whitespace, including anything containing "unix"
 
@tripleee thanks
 
from your limited problem statement, I guess you want something like (?:JOIN|FROM)\s*(?:UNIX)?(\S+) (to skip UNIX and match whatever comes after) or perhaps (?:JOIN|FROM)\s*(?!UNIX)(\S+) to not match the strings where the whitespace is followed by UNIX
also perhaps you actually want \s+ to force at least one whitespace character before the match -- probably that's actually what you are really looking for
 
5:55 AM
@wim *claps*
 
 
2 hours later…
user11702787
7:34 AM
trying to understand why this loop gets still executed
 
user11702787
`index = 0`
`n = 7` `data_added = False`
`while not data_added and index !=n :`
 
user11702787
this is True and False so it shoud not get executed or ?
 
0 != 7 is False?
 
user11702787
of course , looked at rong variable thanks !
 
is there a way to check if something was installed using a local whl or over pip?
I have the odd issue that on one install my cv2 gets recognized by pycharm but on another not. Now I think once I used pip install opencv-python and on another I used a prebuilt whl from this one site which has all the whls(you know which one :P ) but I'm not sure which is which
this one
 
7:51 AM
uhm.. I use pip to install local wheels, what other tool do you use? easy_install? Does it even work with wheels?
 
hmm ok, I worded that badly. I mean is there a way to check if i did pip install some_file.whl or if I did pip install opencv-python(where it downloads it from the net)
like get that info out of the env somehow? Because windows doesn't keep a command history sadly
 
"net" means the global python package index, then. I don't think there is something like "downloaded_from" in the metadata. Unless they use different setup.py files to build to project, it sounds hard to figure our.. maybe the version can be used as a hint?
 
ok, yeah i thought of the version, but ldf.uci.edu has both versions, so I still don't know which is which :P
but yeah, if it annoys me enough that cv2 is underlined red, I will test both ways and figure it out
 
8:25 AM
configargparse is sooooooooo goooood <3 I don't know how I could program without it
 
What kind of algorithm will find the longest repeating substring from a given string? Here I mean that a substring must be repeated twice without any letter between the repeated parts. For example, if a string is hfhfggccaggccagccafff, its longest repeated string is ggcca. But if the string is about 700000 characters long, how one can find the longest repeated string?
I was wondering if one could use regular expressions for this, but I got a wrong answer.

import re

s = 'hfhfggccaggccagccafff'
def find(s):
r=max(re.findall(r'((\w+?)\2+)', s), key=lambda t: len(t[0]))

return r

print(find(s))


Output is ('hfhf','hf') instead of ggcca.
 
@Hakaishin I found a difference. for whatever reason, gohlke doesn't package the license into the metadata. So you can just search for opencv_[...].dist-info in the site-packages where it was installed into, and if there is a LICENSE.txt in there, then it was fetched from pypi. and if there isn't, it's from gohlke.
 
@Arne <3 thank you very much
 
np, happy to help
 
Hmmm both have no license.txt, but I just saw one has a direct_url.json
haha cvs metadata is funny:
Home-page: http://opencv.willowgarage.com/
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Platform: UNKNOWN

UNKNOWN
 
8:33 AM
My strategy would just have been to look in the downloads folder or the recycle bin for the .whl, both terribly flawed
 
I get the previous UNKNOWNs but the last one you feel the frustration of the program, it doesn't even know, what field is unknown, it's just unknown :D
@roganjosh I did that :P But my genius decided as it seems, to download the whls on both pcs and only use it on 1 :D Luckily there is the direct_url.json. Seems like installing it from the file let's pycharm recognize it, whereas using pip install opencv-python doesn't
in the direct_url.json I had: "url": "file:///C:/Users/<username>/PycharmProjects/whls/opencv_python-4.1.2-cp37-cp37m-win_amd64.whl"}
 
@Hakaishin the bottom of the metadata is where the long_description will be pasted. That's a seriously borked build process, I am surprised the code is working at all
 
well, I found out during my master thesis, how hard it is to build stuff. So I'm very greatful, that the website is doing it for me, because it works, be it a bit borked :D
 
9:08 AM
hmmm still no luck. Even after invalidate cache and reeindex. Pycharm refuses to see cv2 on 1 pc. I can see two differences and was wondering what do you think I should check first. 1 is that on the setup where pycharm doesn't recognize cv2 the env is outside of the project folder and the version of python is 3.8 and cv is 4.2. On the working setup I have the venv inside the project and python 3.7 and cv 4.1.
So which would you test first, moving the venv inside or changing the python and cv version?
 
I'd probably update pycharm and restart the pc
 
what do you mean with update pycharm, like the python version?
because the pycharm versions are the same
 
Can someone who knows Python look at the line header = self.header_structure.parse(raw)in the following Python program and tell me what the parse() method does?
 
@MyWrathAcademia header_structure is a Struct; so it calls the method parse in the Struct class. Anything more than that requires familiarity with the Struct class, more than general Python knowledge
 
Does anyone know of a stack overflow chat group for Google Cloud Firestore questions?
 
9:23 AM
it seems to come from pypi.org/project/construct
 
@MyWrathAcademia You need to look here
 
man, pcs are weird. I just uninstalled opencv-python and then installed it over pycharm package manager(which uses pip) instead of using pip install and now pycharm see it. Well goal achieved I guess
 
construct.readthedocs.io/en/latest/basics.html#structs looks like a reasonable introduction
 
@Hakaishin I meant pycharm itself. sometimes it needs an update to work well with new python versions, and 3.8 is still a bit fresh
 
@Arne yeah, that would make sense. But I already got the newest one. Looks like installing it from the internet instead of the edu site works. Now I also have a license.txt
 
9:28 AM
good to hear. On the one hand I wonder why a regular pip install didn't work. On the other, I am burned out on investigating IDE inconsistencies for at least two lifetimes
 
I think it wasn't about the pip or using the pycharm gui, it was the source of the whl. the lfd.uci.edu didn't work for python 3.8. But the online opencv-python did work. Strangely on the other setup the lfd.uci.edu did work. Because I clearly used that one, as can be seen by the missing licence.txt and the direct_url saying file:// blabla. What I could kinda imagine, but what is weird too, is that the opencvp bundle from ldf.uci.edu worked for 4.1 but not 4.2. But that's only a guess.
It's weird anyway ¯_(ツ)_/¯
 
The wheel was for python 3.7, though
 
yeah on the other setup I also have python 3.7.
 
10:11 AM
@tripleee Thanks
@roganjosh Thanks.
 
10:22 AM
"I'll just help vectorize this easting/northing to lat/long question. We don't need that pesky PyProj slowing us down. Let's find the formula"... holy hell
 
10:37 AM
@roganjosh I'm not familiar with structs, or Python. Can you translate what the following Struct does?
self.header_structure = Struct(
            'magic' / PaddedString(12, 'ascii'),
            'version' / Int32un,
            'unknown' / Array(10, Int16un)
Say you call it with this:
raw = f.read(36)
            header = self.header_structure.parse(raw)
I'm thinking it converts the first 12 bytes to a string?
As for the fields version and unknown, I don't know.
When defining a structor, what goes on the right side of the / operator, is it the data type of the field or a method?
 
@MyWrathAcademia it sets up a memory structure so you can find fields within a memory region of a particular size with a particular structure ... so yeah, it says the "magic" member is a string starting at offset 0, "version" is a 32-bit int starting at offset 12, "unknown" is an array of 10 16-bit ints after that
looks like the thing after / is a type declaration
and I guess the un suffix means unsigned
 
n = native endianness
 
10:54 AM
/me postpones attempting to explain endianness, though I'm guessing you're probably not familiar with that either then
 
Everything you need to know about endianness summed up: If you're creating/parsing data that has been or will be exchanged between different computers, don't use native endianness. The end.
 
ugh, hearing that word makes me cry
also
 
11:09 AM
@tripleee Thanks. What offset does the member "unknown" start from? Is it offset 16 since Int32 is represented by 4 bytes?
@tripleee Noo, I am familiar with endienness. It is is simply the byte order when reading bytes. So little endian is reversed, and big endian is forward.
@Aran-Fey good catch.
@Aran-Fey so native endianness in Python is little endian, right?
 
@MyWrathAcademia Native endianness in Python is native endianness.
Native endianness does not depend on the language, it depends on the platform.
 
@MisterMiyagi Aah, I see. Thanks.
@Aran-Fey I'll keep that in mind, thanks.
 
@MyWrathAcademia makes sense, yes
 
11:27 AM
@tripleee thanks. Then in that case, after the member "version" there are 16 bytes left. Since 16 bits is equal to 2 bytes, an array of 10 16 bit ints is the same as an array of 20 bytes. So using the native endienness and 2 bytes per digit, those 20 remaining bytes are converted to an array of 10 digits which gives a single integer? Is this correct?
@tripleee I mean after the member "version" there are 20 bytes left
 
@MyWrathAcademia I have no idea how those are used; "unknown" probably means they are not well-defined or properly documented
but the space they occupy is 20 bytes, yes
 
@tripleee thanks.
 
it's not unusual to reserve a few bytes in a structure for possible future needs
though then I would expect "reserved" or perhaps "undefined"
 
@tripleee I'm trying to understand the Array(10, int16un) part.
Does Array(10, Int16un) mean every 2 bytes is an integer?
 
there is an array of length 10 and each element is a two-byte integer but the label name etc suggest that this is just a way to say "skip 20 bytes somehow"
so if you populate it with the bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13 0x14 it encodes the ints 0x0102 0x0304 0x0506 ... or with opposite endianness 0x0201 0x0403 0x0605 ...
but we obviously have no idea what those ints are used for or how they are interpreted
 
11:42 AM
@tripleee Brilliant example.
@tripleee so the member unknown does not hold a single int, instead it holds an array of ints?
 
> In this technical and political examination of byte ordering issues, the endian names were drawn from Jonathan Swift's 1726 satire, Gulliver's Travels, in which civil war erupts over whether the big end or the little end of a boiled egg is the proper end to crack open.[3][4]
5
Awesome
 
Awesome indeed.
 
@MyWrathAcademia yeah, that's why it says array(10, ...)
 
Also TIL positional notation. This page is a gold mine.
 
Keep them coming, beats everything else on my plate today.
 
11:45 AM
@AndrasDeak Wikipedia as a whole is a gold mine.
@tripleee Thanks. Very clear now.
 
I always thought that the "end" refers to the end of the stream. Which would swap the meaning of little and big endian. Because the subject is not confusing enough already.
 
@AndrasDeak I need to inspect some eggs, I assumed both ends of an egg were equally sized.
 
@MyWrathAcademia oh not at all!
 
What shape is an egg?
 
capsule-shaped eggs are creepy
 
11:47 AM
Are they not spherical, correct me if I'm wrong?
 
@MyWrathAcademia nope
They're asymmetrically oblong
 
they're... egg-shaped
 
At least chicken eggs. There's a sharper and a flatter side.
 
unless you're a physicist en.wikipedia.org/wiki/Spherical_cow
wikipedia has many examples en.wikipedia.org/wiki/Egg
 
if you're a more decent physicist, they have C∞ symmetry :P
 
11:49 AM
@AndrasDeak We have an egg connoisseur.
 
dig the 3d model
 
I don't want to brag but I'm pretty good at chicken egg shapes
 
I actually have some free range eggs. Will confirm.
 
Hi guys
 
@AndrasDeak since there is a sharper and a flatter side, which side does the baby chicken hatch from?
 
11:51 AM
Is this chat for deep learning too?
 
@George hello
@MyWrathAcademia no idea.
I'm not a flipping baby chick psychiatrist
 
sure youre not
 
@tripleee haha. I learned something new today.
@AndrasDeak I'm thinking the baby chicken hatches from the pointy side. Because the bottom side has to be where most of its weight is.
 
@MyWrathAcademia it might hatch on the side of the egg. The top and bottom support the hen's weight, but the side might be easier to crack.
 
@AndrasDeak hmm, interesting line of thought.
 
11:57 AM
But anyway it's easy to crack an egg from the inside. It's designed to withstand forces from the outside.
 
@AndrasDeak Yeah, makes sense.
@AndrasDeak You're right that a baby chicken most likely hatches from the side. After all an egg does not stand freely on its own, it just rolls unto its side.
 
Well I imagine there's no room for a chicken to move before hatching, so it hatches wherever its beak is when it's ready to emerge. It's just that its orientation in the egg won't be too random, there'll be a likely place where it ends up before hatching.
 
Yes, agreed. May be one day I (or someone) will use python to calculate the probability of a chicken hatching from any of an eggs sides.
I will use a spherical cow model.
 
 
2 hours later…
1:39 PM
Andras, delete as I'm on mobile please
Correct one:The baby ratchets his body around the interior of the shell until he has completed a full circle of peck marks. After that he pushes on the pecked area for hours until he has completely broken free.
As Andras said, it's going to hatch out of the side @MyWrathAcademia, but not because of support. It's because it has a larger surface area.
In other words, the egg is cut in half. Just look at Google pics and you'll see
 
2:01 PM
@JossieCalderon thanks. Where did you get this from?
 
@George not very much, but here and there some ml pops up. I'm doing a bit of it and I heard of a few others who did
 
animals.mom.com/chicken-hatch-out-its-shell-9660.html contains the "ratchets his body" quote verbatim, which seems to link to chickscope.beckman.uiuc.edu/explore/embryology/day21/… as its reference*, which is apparently a re-illustration of chickscope.beckman.uiuc.edu/resources/egg_to_chick
(*I think. The javascript on the first page is buggy to the extent that I can't find the link again.)
If the second link is to be believed, the chick typically emerges from the egg cap, i.e. the less pointy end
 
@Kevin thanks.
@Kevin @AndrasDeak So my initial guess might have been correct. Interesting.
@Kevin I guess it makes sense that the chicken emerges from the longitudinal (i.e. longest) side.
 
2:16 PM
I'm bothered by the fact that 90% of the Google image search results for "chicks hatching" are stock photos of clearly-not-newborn chicks emerging from clearly fake shells, often broken in ways that are aesthetically pleasing at the expense of being scientifically correct
The chicks should not be fluffy and cute, they should be damp and kind of gaunt
 
any socket experts? Using the free too tcp port listener tool i receive the request the server sends
using following python code i get nothing
import socket


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 5005))  # Bind to the port
s.listen(5)
print("Starting to recv")
while True:
    c, addr = s.accept()
    print("Connected to ", addr)
    msg = s.recv(1024)
    print(msg)
@Kevin and lol, as a vegan symphatisant I agree that the more realistic it looks the better
symphatetic? what's the word
 
"Sympathizer", perhaps
 
sympathizer ah yes that's the one :P
eh a problem for tomorrow bye guys
 
Most of the eggs you can buy at the grocery store are unfertilized, so there's not much gross-out potential if a vegan protester shows pictures of slimy chicks to people in the egg aisle. "I bet you'd hate to see one of these while you're getting breakfast ready" is an implausible scenario
If realism is not a concern and you just want to make the shoppers queasy, there are probably grosser pictures out there on the Internet. I nominate the pacific geoduck as the ideal combination of "nasty" and "not nasty enough to get you arrested for presenting it in public"
 
2:31 PM
@Kevin Emphasis on the most, eh? Which makes the plausibility slightly greater.
 
I'm hedging my bets because I don't know how things are in other cultures. For all I know, they have an entire shelf of fertilized eggs in every store in outer Elbonia. If I were talking about my grocery store in particular, I'd put it at 0.01% odds.
 
@Kevin @MyWrathAcademia Thanks, Kevin. As you can see, this backs up my statement: The shell is cut in half.
I wanted to use the same exact images you posted but I was on mobile
 
@Hakaishin what do you mean by "free tcp port listener" ? what type of packet you've sent then ?
 
I have a camera which sends some data i can chose protocol=tcp, ip and port. I don't know more about the sender. Listener I used the program called free tcp port listener tool
 
@Kevin Sure, but if you have 3 eggs 3 mornings a week, that's five-ish times a year. Similarly with double-yolkers, although I've seen less of those since I moved to the US.
 
2:43 PM
with which I could receive the packets from the camera, but with the above python code, which I thought should also listen to tcp packets I didn't get any data
 
The Internet tells me that a fresh fertilized egg that has been refrigerated to grocery standards will probably have an embryo that resembles a small white dot. You might not even notice it if you're not looking.
 
@Kevin Maybe I've been mislead, I always thought the ones with a little red/blood in them were the fertilized ones?
 
More specifically, my source is treehugger.com/green-food/…, under the "How Do I Hatch My Own?" heading
 
Hello
I have code for optimization.
Can i ask here?
 
Oops, I misread. Both fertilized and unfertilized eggs have the white mark. The difference is the shape.
@ChrisP Yeah.
 
2:50 PM
Or should i post in stackoverflow?
Well it's 123 lines of code
Where can i put it?
 
Stack Overflow is not very receptive to code optimization questions whose code is functional, but long/slow/un-idiomatic. That's better suited for Code Review.
@ChrisP dpaste.com is a decent choice.
 
@toonarmycaptain According to healthline.com/nutrition/bloody-egg#causes, red spots are unrelated
 
One issue is that when user's drag and drop the timer circle, then i have to wait few seconds to apply the changes.
 
@Kevin Huh, TIL. Guess you wouldn't notice then.
 
Ok, I see, no sexual body part mentions are allowed. @AndrasDeak I didn't meant to insult.
 
Language policy is a little fuzzy around the edges, but let's err on the side of caution for the time being
 
Thanks
 
Gratuitous mentions of large snakes and pythons notwithstanding ;)
 
2:58 PM
:D
 
@Kevin Do you want the mp3 file i use?
 
If the problem is replicable with any mp3, I can just use my own
 
Ok. Notice: change the self.total_duration_in_milliseconds variable.
 
@Hakaishin so to minimize that into a shorten road. you do have a camera, which is sending some packets to "x" which you don't know it. and you are trying to listen to those packets instead of "x" or you would like to intercept the outgoing packet to "x" while you are locally within the camera?
 
@Kevin Also check why if i close the tinker window while mp3 is playing a RunTimeError is oquered
 
3:05 PM
If I had to guess, I'd say that a RunTimeError might occur if the script finishes executing while audio is still playing
 
How can i catch this error?
If x_button is pressed then stop audio and close main window.
 
Closing the tkinter window normally causes root.mainloop() to return, and mainloop() typically appears close to the end of the script
I believe it's possible to create an event handler for WM_CLOSE window events. I'm not sure how exactly to do that, but I'm sure it's explained somewhere online
But perhaps that's not necessary to begin with, if you put your "stop audio" code right below player = Mp3Player()
 
124
Q: How do I handle the window close event in Tkinter?

Matt GregoryHow do I handle the window close event (user clicking the 'X' button) in a Python Tkinter program?

 
Ok, so I feel very brave saying this so much more experienced Python developers than myself, but I think I may have come up with a better way of dealing with Python dependencies than using a different virtual enverioment for every project.

Can I get you guys thoughts on it please?
 
There you go. I'd say that approach is more useful for scenarios where you want to do something with the window object before it ceases to exist, or if you want to override the user's choice and keep the window open forcibly
 
3:11 PM
@Kevin haha, yeah most of those photos are staged.
 
if you just want to do something with your audio after the window is gone, then you don't necessarily need the window object for that
@JamesMcIntyre Sure.
 
@JamesMcIntyre I know little about dependency management (never bothered releasing anything), but you have my curiosity
 
My expectation is that most of us will say "ehhh, I still think virtualenvs are better", but there's no harm in hearing novel ideas
 
Ok, this code is for radio streaming connection.
You believe AudioSegment is the right choice for this task?
 
@Kevin that would be quite a sight.
 
3:14 PM
@ChrisP I'm not too familiar with pydub specifically or audio libraries in general, so I can't really say
 
I also want to mix sound from microphone.
@Kevin ok!
 
@Kevin I saw duck and being cautious I still expected something fluffy and feathery but my god that looks nasty. I'll try to forget what I saw, eeeww.
 
@Kevin Those are still the fluffy and cute variant.
 
I suspect it's possible to get more responsive drag-and-driop behavior, but I don't know enough about the AudioSegment interface to recommend anything concrete
This is based mostly on my general expectation of how media streaming interfaces are typically set up, based on my experience wresting with mp4s from Youtube
 
@JamesMcIntyre Shoot!
 
3:20 PM
@MisterMiyagi If the ones I checked in green are also staged, and real chicks are even damper and gaunter, so much the better
 
Ok, so I am that much of an inexperienced Python developer that I've been installing all of my modules to my global enviroment and only recnelty came foul because of it with conflicts appearing and so understand this is at least one of the reasons why people use virtual enviroments.

I really didn't want to create a vitural enviroment for every one of my Python projects and have constantly switch between enviroments. This also means duplication of your externally installed modules. Anouther issue with it is that if you want to use two modules which conflict so that they need different versi
 
I found the middle one rather suspicious, but I figured, if you're going to stage a hatching, you may as well wait until they're fully cute
 
@Kevin The last few I fed to my cats didn't look quite as well groomed, to say the least.
 
you what?
 
obviosly this could be automated:

import sys

sys.path.append('/home/jamesmcintyre/.local/pipx/venvs/opencv-python/lib64/python3.8/site-packages')

import os

CL = os.getcwd()

os.chdir('/home/jamesmcintyre/.local/pipx/venvs/opencv-python/lib64/python3.8/site-packages')

import cv2

os.chdir(CL)
 
3:23 PM
why the chdir?
it's already on the path.
 
It was the only way I could get it to find the isolated module
it's not in the path. It was installed with pipx so if you just do "import os" it says that it can't find it
*"import cv2"
 
I'm surprised to hear that it's even possible to have two modules in different virtual environments, and which can both be imported into the same environment
 
it's entirly containerised and so can't conflict with other modules which use different versions of the same dependensy. They each have their own versions
 
I'm tempted to say "this defeat the purpose of virtual environments to begin with: protecting your wider system from whatever's inside the venv", but on second thought, if the wider system is consensually entering the venv and pulling something out, I guess it should be allowed to do that?
 
it works. That example then goes on to use the cv2 module in the current directory.

The reason for doing it is to stop module conflicts
 
3:27 PM
sys.path.append('/home/jamesmcintyre/.local/pipx/venvs/opencv-python/lib64/python3.8/site-packages') puts that in the PYTHONPATH, so chdir should not be required. So I'm with MrMiyagi - why the chdir?
 
I don't get what that code achieves. You have a virtualenv in which cv2 is installed, and you use some weird sys.path hack to import a module from that virtualenv. What's the point of this?
 
I think that they can use one install of opencv in 5 different envs
 
I don't get it. You explicitly add the site-packages to sys.path - it's on the import path, then. There is no need to os.chdir to it as well.
 
"It's annoying when two libraries depend on different versions of the same library" is a valid problem. What is the usual solution? fork the upstream library and hack it to be compatible with both?
 
sorry that append shouldn't have been there
 
3:28 PM
The way I read it, it sounded like a mix-and-match kind of deal using a small set of library versions installed somewhere
 
Note that this only "containerises" the immediate dependencies. Secondary dependencies that are shared by multiple primary dependencies will depend on the import order.
 
that was from earlier non working code
 
Ok, well, the sys.append was definitely throwing us all off.
 
@αԋɱҽԃαмєяιcαη I have a router, cam and pc. Cam sends tcp packets to my pc. I have a tool which receives them and I can read them. I want to do what the tool does in python :)
 
Sorry, I rushed the copy a wee bit after my long message.

Should be just:

import os

CL = os.getcwd()

os.chdir('/home/jamesmcintyre/.local/pipx/venvs/opencv-python/lib64/python3.8/site-packages')

import cv2

os.chdir(CL)
 
3:30 PM
It sounds like there isn't too much objection here to the idea of "what if you could import two versions of one library simultaneously?", and we're mostly bikeshedding* about the best way to do that
 
@AndrasDeak Feed day-old chicks (dead and frozen) to my cats. Says a lot that this is one of the more humane ways for them to go.
 
So if I understand correctly you'd create a virtualenv for each dependency, instead of a virtualenv for each project?
 
@MisterMiyagi <unsettled Tom meme>
 
What's the benefit?
 
3:31 PM
which means that if two of your modules had a conflict... it wouldn't matter
 
(*cue argument about whether it really counts as bikeshedding, or if it rises above that level to True Importance)
 
(becuase each one of your dependencies has it's own versions of their dependencies)
 
By "module" you mean your own projects or dependencies of your projects?
 
@JamesMcIntyre Can you clarify what you mean by "modules conflict"? You can still have each module only from one location.
 
And what kind of conflict?
 
3:32 PM
@MisterMiyagi I rate my current squick level at one notch above "feeding mice to snakes" but agree with your assessment of the relative humaneness
 
If you're talking about a conflict in the sense that you have moduleA which depends on version 1 of moduleC, and moduleB which depends on version 2 of moduleC, then installing moduleA and moduleB in separate virtualenvs won't help you
 
Hmm! That's surprising to me
 
Ok, so lets say you have your own project which uses module A but also module B

Module A has it's own dependency of module Z but this needs to be version 1 or it doens't work

Module B also uses module Z as a dependency but it requires version 2 to work or it doens't work

If your project is in a vertual enviroment but this envirment has both A and B installed, one will be broken and your project doens't work.

With the method I'm suggesting, your project does work
 
I'm afraid it won't. Modules are application global. You still have only one version of module Z.
 
Right. As soon as you import any version of module Z it will be cached in sys.modules, and subsequent imports will use that exact same version of module Z
 
3:38 PM
recbg
 
With my method you've installed module A with pipx and so it's installed it into it's own vertual enviroment with version 1 of module Z

pipx has installed module B to it's own environment with version 2 of module Z
 
All a virtualenv really does is that it gives you a different location to install modules, and a matching module search path. If you use a sys.path hack to import something from a virtualenv, you're practically defeating the purpose of a virtualenv
 
[I cross off "defeating the purpose of..." on my Novel Idea Bingo sheet]
 
Consider also the opposite problem: If you do manage to have two version of the module, that affects all of their content. E.g. if any part of the common code does except module_z.ExZedPtion: it handles only one of the versions.
 
You're assuming that a module installed in a virtualenv will import its dependencies from that same virtualenv, but that's not true
 
3:42 PM
@JamesMcIntyre You may want to take a look at sys.modules. Basically the first time you do import foo, the module is loaded and put into sys.modules. Every subsequent import foo will fetch the already loaded module from inside sys.modules.
 
You can import two versions of the same module with some horrible hacks, but as MisterMiyagi pointed out, it usually only causes you a headache
 
frankly the sys.modules is pretty much the only reason why modules are global.
 
But surely even importing B breaks A. Worst case sonario you import A again before you use it. You couldn't do this if they were both globaally installed as A wouild simply be broken?
 
In your scenario, B is broken in any application that previously imported A.
 
Proposal: create two fully sandboxed virtual machines that import A and B respectively, with the correct versions of Z. Both VMs communicate with your real script via TCP.
 
3:45 PM
No one in their right mind would do such a thing...
ahem
Pipes are much better than TCP for this.
 
Aw man, did I reinvent amazon web services again
Or was it kubernetes this time
 
@JamesMcIntyre Importing a module again changes nothing unless you mess with the sys.modules cache first
 
So even if you still can't use A and B in the same script. This way of doing things is a tleast as good as creating a vertual enviroment for all of your projects and possibly better as your probably going to use the same external modules over and over again so you'll save disk space by only having them installed once. You'll also save yourself the headach of creating and switching between virtual enviroments for every project.
 
But in exchange you need to setup a system that allows each project to import each of its dependencies from the correct virtualenv
 
all you need to do to do that is install with pipx rather than pip
 
3:51 PM
I, too, find venv-switching annoying, but I solve this problem by just installing everything globally and hoping very hard that nothing's incompatible
 
But why would anything installed with pipx be importable?
 
It's actually worked pretty well for me so far
 
@Kevin James Powell had a hack where there were both Python 2 and 3 in the same exe. Guess you could have 2 python 3s if you're insane enough.
 
@Aran-Fey importable?
 
@JamesMcIntyre Yeah. Just because you execute pipx install moduleZ doesn't mean that you can do import moduleZ and expect it to work
 
3:53 PM
No but this works and could be turned into a simple function:

import os

CL = os.getcwd()

os.chdir('/home/jamesmcintyre/.local/pipx/venvs/opencv-python/lib64/python3.8/site-packages')

import cv2

os.chdir(CL)
 
Where do you put that code, though?
Surely you aren't going to have that code inside your project's source code, right?
 
Surely, Mr. Feynman :P
 
No, you create a function called somthing like:

importx(cv2)

def importx could be in a module elsewhere.
Also, the dependency problem could be fixed by chagning the name of conflicing sub dependencies
 
And then what happens when you publish that project? Do you manually change all importx(...) to regular import statements?
Do you leave the importx calls in and require the user to pipx install all dependencies?
 
No, you publish your module which defines importx along with the rest of your code
 
3:57 PM
But importx won't work on my machine. I don't have any pipx-installed modules
/home/jamesmcintyre doesn't even exist on my machine
 
simply make importx check to see if the module is pipx-installed, and if not, pipx-install it. </half-serious>
 
I'm not sure to be honest.

I still a newbie so I do bow to you guys superior knowlage and experience. I think I will find this useful in my line of work until there is an issue.

In terms of publishing there may have to be somthing already built into pipx or somthing else for it to work.
to be fair, I'm a fan of portalbe code so I think the easiest way to publish would be to publish along with dependencies
 
I basically see the advantage of re-using modules (which is incidentally the opposite of containerising). As for muddling with path/chdir/... to import each correct module, I don't see that as a win over activating a venv once.
 
I'm a big fan of personal projects that may or may not reinvent the wheel, so I say, continue using and extending your idea and see what shakes out
 
@JamesMcIntyre Erm, if you publish with dependencies then you don't re-use existing modules, do you?
 
4:03 PM
The best way to identify inconsistencies in a concept is to carry it to its logical conclusion and beyond
4
 
Anyways, if you want to automatize the path magic, look at import hooks. Those could be used to dynamically look for specific modules at specific locations, without changing the import places.
 
It's more about the modules you install "simply working" rather than having to create a virtual enviroment for every one of your projects
I will look into import hooks MisterMiyagi, thank you
 
Oh boy, I wouldn't say "look into import hooks" to my worst enemy
they're, to put it mildly... a mess
 
I think the world is moving in a more portable code direction. Just look at Google Fusia and Harmony OS. Both OSes of the futre and both built on micro kernals.

Shared dependencies I feel are asking for trouble
 
For a historical perspective, I'd like to point out that many languages have been able to import multiple different versions of a library for decades. The name of this concept, DLL Hell, should give you an idea about its ease-of-use
 
4:11 PM
@JamesMcIntyre I don't get your reasoning. What you are advocating for are shared dependencies.
 
I'm aguing that all of your dependencies are isolated and so module A does not require anything that module B requires. They both have their own versions of module Z self contained
you sharing it for your own projects but it breaks because your update somthing then that's your own fault. it shouldn't break because somone else updates somthing
 
Sure, module Z would not be shared (ideally). Yet module A and module B would be shared.
 
Yes, for your own but only for your own projects.
 
I believe the current idiomatic solution is "find the github pages for modules A and B and harass them until they get off their butts and upgrade to module Z v.2020"
 
4:16 PM
Let us quietly ignore the most likely failure mode, "what if module B is abandoned and making my own updated fork would be really really hard?"
 
Why would B being abadondoned cause you a problem?
 
Then harassing them on their github page will be unsuccessful, since the maintainer is kicking back on a tropical island somewhere
 
Just pester the moduleA devs to downgrade from moduleZ v2 to moduleZ v1 instead
 
So you guys agree that my soltion would fix that?
 
@Aran-Fey Hmm, could work. "Please don't drop compatibility for Python 2.7 :'-(" convinced quite a lot of popular libraries for quite a long time.
@JamesMcIntyre I think the idea of "have separate environments so both modules can import different versions of Z" is a promising idea. I am unsure whether your specific implementation does that flawlessly. I couldn't completely follow the technical discussion of module caching and pipx-importability etc etc.
 
4:23 PM
@JamesMcIntyre Mmm, yes and no. It could solve the problem, or it could cause different problems of the sort that MisterMiyagi explained
 
I'm honestly not sure about that either but even if that did cause a problem, I dont' think it would be that hard to build in the function of renameing sub dependencies to counteract that
 
Ah, there's the kind of thinking I like to see
 
I'm tempted to start a public github repo called "importx" unless you guys think my whole concept is crazy?
 
Programming is the art of plugging holes in your sinking ship and hoping you're done before you run out of fingers
I don't think the concept is crazy. The day before ImportXCorp makes its IPO, call me and let's talk stock options :-)
 
I don't think it's crazy, but I do think that it'll take more effort to implement than you realize. Importing two versions of a module is easy; what'll be difficult is installing the dependencies correctly
 
4:28 PM
Coming to the conclusion of "wow, this is much harder than I thought" is a valuable and educational outcome of a personal project
 
I'm not even sure if it's possible to hijack pip to such a degree that it would let you install two versions of the same dependency. So projects using your idea/module might not be pip-installable
 
Shrinking the territory of "things I don't know that I don't know" and growing the territory of "things I know that I don't know" is half the battle
 
So it would all be built off of pipx not pip.

If hypothically I ever got my repo into pypi, you could only use one import statement (import importx) and then you could just importx any modules you've pipxed
 
Whoever asked about pydub - AudioSegment is fine for what you were proposing
audio processing is just one of those signal processing tasks which made me learn MATLAB but pydub, pyAudioAnalysis & pyAudioProcessing have been useful these last few years switching that over (which is nice)
 
wim
4:54 PM
@JamesMcIntyre The need is there for such a feature but it is currently worked-around with vendoring.
 
@wim what's vendoring?
 
wim
when an app or library packages up exact versions of the dependencies they need
so when user code would import msgpack for example, pip would from pip._vendor import msgpack
this allows pip to "use" msgpack==1.2.3 while user code can have installed whatever version user wants, without conflict, because the pinned code is namespaced by _vendor in sys.modules
your idea won't work as written because you didn't do anything to evict from the sys.modules cache
 
01:00 - 17:0017:00 - 00:00

« first day (3510 days earlier)      last day (1435 days later) »