Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
LochNessMonster
Feb 3, 2005

I need about three fitty


Dominoes posted:

Type 'python' in powershell. What do you see? I'm out of ideas.

Python results in the Python shell being opened. Pip list works too, it's just the conda commands that aren't working.

I installed miniconda on my work laptop and that works perfectly fine. Guess I'm gonna try and install mini conda on my home machine too.

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Loch - I've no idea why the Anaconda-specific commands aren't working.

shrike82 posted:

Do most of you run Python in Windows?

Package issues like this and the difficulty getting tensorflow running on Windows drove me to a dual boot Ubuntu setup.

It's a pain in the rear end to setup but I've found switching to a Linux build helpful in mitigating stuff like this.
Have you tried getting Python 3.6 running in Linux without Anaconda? That was really frustrating for me, and I never got it working!

Dominoes fucked around with this message at 12:16 on Jun 6, 2017

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Dominoes posted:

Loch - I've no idea why the Anaconda-specific commands aren't working.

Have you tried getting Python 3.6 running in Linux without Anaconda? That was really frustrating for me, and I never got it working!

were you trying to replace the system python version, because you really don't ever want to do that. building from source with configure, make and make altinstall then using python3.6/pip3.6 works fine for me on centos7. literally did this today as part of an automated setup for a vm i need to do stuff on

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

shrike82 posted:

Do most of you run Python in Windows?

Package issues like this and the difficulty getting tensorflow running on Windows drove me to a dual boot Ubuntu setup.

It's a pain in the rear end to setup but I've found switching to a Linux build helpful in mitigating stuff like this.
I have two separate Python installations on my home computer. One is a Python 3.6 installation with Anaconda for Windows, the other is Python 3.5 installation in Bash for Windows, which is where I use Tensorflow. For almost everything I can use them interchangeably.

In the brave new world of Bash for Windows, you don't really need to run VMs or dual boot if you don't want to.

Ghost of Reagan Past fucked around with this message at 12:35 on Jun 6, 2017

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
i'm a windows 7 holdout on my work laptop for reasons, does the windows subsystem for linux fix all those annoying things like not being able to run gunicorn because windows doesn't have fcntl and so on?

Dominoes
Sep 20, 2007

Dex posted:

were you trying to replace the system python version, because you really don't ever want to do that. building from source with configure, make and make altinstall then using python3.6/pip3.6 works fine for me on centos7. literally did this today as part of an automated setup for a vm i need to do stuff on
I tried everything! At one point I had all 3 versions installed at once, but couldn't get pip to work with 3.6. Somehow broke my system beyond repair (ie fixing would be more difficult than starting fresh) troubleshooting it.

Dominoes fucked around with this message at 14:32 on Jun 6, 2017

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

Dex posted:

i'm a windows 7 holdout on my work laptop for reasons, does the windows subsystem for linux fix all those annoying things like not being able to run gunicorn because windows doesn't have fcntl and so on?
Haven't tried gunicorn, but most syscalls are implemented. Not all, though. Should probably work, and if it doesn't they're working pretty heavily on it so it'll probably be there soon.

LochNessMonster
Feb 3, 2005

I need about three fitty


Dominoes posted:

Loch - I've no idea why the Anaconda-specific commands aren't working.

Thanks for all the helpful pointers over the last few days. I'm gonna try and see if I manage to get it working on my own computer with miniconda. If not I'll just manage my packages and run the applications with bash on ubuntu on windows. Or built a development environment in Virtual Box.

QuarkJets
Sep 8, 2008

Dominoes posted:

I tried everything! At one point I had all 3 versions installed at once, but couldn't get pip to work with 3.6. Somehow broke my system beyond repair (ie fixing would be more difficult than starting fresh) troubleshooting it.

I have no idea how you do that without intentionally installing into system paths. The installer defaults to your home area and will create a standalone anaconda distribution that doesn't mess with any system paths and will definitely just work

It sounds like you maybe tried to replace the system python with anaconda, which is a bad idea

Dominoes
Sep 20, 2007

I think the break involved trying to uninstall 3.5 or 3.6. Multiple versions on the system is awkward at best. In the future, I'd use Anaconda, which sets up things up nicely automatically, or virtual environs. There's probably a clean way to get 3.6 working in Ubuntu, but googling and troubleshooting for hours didn't do it; I'm classifying this one as difficult. It's comparatively straightforward in Windows, due to the lack of system python, and a nice official installer.

Dominoes fucked around with this message at 05:07 on Jun 7, 2017

QuarkJets
Sep 8, 2008

I think in general it's ill-advised to try and upgrade the system Python. So many things will break because they were made to use the specific version of Python that came with the system, so trying to replace it will cause problems

LochNessMonster
Feb 3, 2005

I need about three fitty


RE: Miniconda instead of Anaconda.

Same poo poo, also doesn't work. So I guess it's a computer specific issue. Not going to put more time into this. I'll just run all my stuff from bash and manage packages with pip.

edit:

I'd rather spend more time learning python than learning how to manage packages.

Speaking of which, I'm creating a script that is trying to read some API's and want to write results to a sqlite db. What I'm doing so far is

code:
conn = sqlite3.connect('db.sqlite')
cur = conn.cursor()

def apicall1(input1):
  do stuff
  write to db


def apicall2(input2):
  do other stuff
  write to db


result1 = apicall1(some_input)
result2 = apicall2(other_input)
Is setting up a db connection and then using a few functions to pull data and store it in the db an OK way of doing this or am I being horribly inefficient and/or unpythonic by doing it this way?

I'm creating quite a few functions which probably won't all run all the time. Is it better to create a seperate function that does both the connecting and writing to the db seperately, so something like this:

code:
def write_to_db():
  conn = sqlite3.connect('db.sqlite')
  cur = conn.cursor()
  insert query

results = apicall1(input)
write_to_db(results)
Or go even a bit further and make a function that returns the connection/cursor objects which can be used in the api call functions? Is that even possible, or am I now landing into the __init__ territory I was asking about some days ago?

LochNessMonster fucked around with this message at 12:26 on Jun 7, 2017

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun
You can totally do this

code:
def connect_to_db():
    conn = sqlite3.connect('db.sqlite')
    cur = conn.cursor()
    return conn, cur


def insert(query, cur):
    cur.execute(query)
    cur.commit()

conn, cur = connect_to_db()
insert(query, cur)
insert(query2, cur)

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

LochNessMonster posted:

RE: Miniconda instead of Anaconda.

Same poo poo, also doesn't work. So I guess it's a computer specific issue. Not going to put more time into this. I'll just run all my stuff from bash and manage packages with pip.


Hey, I don't know if it works but you might want to try using the Linux Miniconda inside bash.

LochNessMonster
Feb 3, 2005

I need about three fitty


Ghost of Reagan Past posted:

You can totally do this

code:
def connect_to_db():
    conn = sqlite3.connect('db.sqlite')
    cur = conn.cursor()
    return conn, cur


def insert(query, cur):
    cur.execute(query)
    cur.commit()

conn, cur = connect_to_db()
insert(query, cur)
insert(query2, cur)

Awesome, that is exactly what I need. I haven't come across the conn, cur = connect_to_db() before. Does this mean that whenever conn or cur are used below that line, it'll run the connect_to_db() function to get those variables filled? Not sure if I should call them variables, they're more like connections/handlers right?

Thermopyle posted:

Hey, I don't know if it works but you might want to try using the Linux Miniconda inside bash.

I already used pip on there, I seem to recall that using both is not a good idea. Won't that mess things up?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

LochNessMonster posted:

Won't that mess things up?

No. If you use pip (without using virtualenv) it install packages into your system python install.

When you use miniconda it has its own python install that won't have anything to do with your system python.

FWIW, I always use pip when I'm using miniconda. Mainly because it works just as well as `conda install` does in 99% of cases, and pip is what everyone uses.

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

LochNessMonster posted:

Not sure if I should call them variables, they're more like connections/handlers right?

that syntax is just working with tuples. if you return multiple things like that, you can either catch them all in a tuple or assign them directly to variables

code:
>>> def blah():
...     return 1, 2
...
>>> a = blah()
>>> b, c = blah()
>>> print(a, b, c)
((1, 2), 1, 2)
>>> print(type(a), type(b), type(c))
(<type 'tuple'>, <type 'int'>, <type 'int'>)

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

^^^ :v:

LochNessMonster posted:

Awesome, that is exactly what I need. I haven't come across the conn, cur = connect_to_db() before. Does this mean that whenever conn or cur are used below that line, it'll run the connect_to_db() function to get those variables filled? Not sure if I should call them variables, they're more like connections/handlers right?

connect_to_db() returns 2 values, as a tuple (you don't explicitly need parentheses, it's the comma separation that does it). When you do conn, cur = connect_to_db(), you're unpacking the two values in that tuple and assigning them to those two variables. There's basically two things coming out, so you can specify a pair of variable names to assign to

And those names are variables, they just point to objects representing a particular connection etc. What you want to call them depends on whether you're talking about the variable itself (if its value changes) or the thing it represents (if you assign it once and just want to refer to that specific thing). So in this case I think calling them variables makes sense, since you're specifically talking about assigning a value to the label. You'd probably just call it a handler after that though, since you're talking about what it represents now

Cingulate
Oct 23, 2012

by Fluffdaddy
Now tell them about ... the stars.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

No you fool they're too powerful!!

LochNessMonster
Feb 3, 2005

I need about three fitty


Thanks for all the great advice and explaining these concepts. I think I've learned 20% from automate the boring stuff, 20% from the python docs / stack overflow and the rest from this thread.

I'm not much of a creative type but I really love building stuff with python. So thanks for being patient!

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
fluent python owns

Eela6
May 25, 2007
Shredded Hen

Malcolm XML posted:

fluent python owns

:agreed:

Hemingway To Go!
Nov 10, 2008

im stupider then dog shit, i dont give a shit, and i dont give a fuck, and i will never shut the fuck up, and i'll always Respect my enemys.
- ernest hemingway
ok, I'm semi-python competent, at least for crunching networkx alorgorithms, but I have a thing I want to do with a gui. I tried a long time ago, I'm trying again now, but I just can't understand how tkinter works.

Here's what I want to see

This is my dream. Maybe add a canvas in there at some point if I'm feeling REALLY ambitious
So I try to use grid, and this is in my create widgets:
code:
text1.grid(row=0,column=0,rowspan=1, columnspan=1)
text2.grid(row=1,column=0,rowspan=1,columnspan=1)
self.okButton.grid(row=1,column=1)
and I always get

I mean, at first, I specified the first text take more rows and columns while the one below just take one row, and I still got the same thing
and tried changing the second Text to Entry, and things still suck, how do I get the sizes to work in this application

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!
I'm using PyCharm and a remote interpreter inside a Docker image. It's neat but it looks like PyCharm spawns a new container each time I run some code. Is it possible to tell PyCharm to use a persistent container instead?

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



What's the best way to go through a pandas dataframe and convert all of the values to a different value if they meet a set criteria? I've got a data frame representing grayscale images, where each cell is a value between 0 and 255, and I'd like to just convert this to black and white by changing anything that's not zero into a 1 prior to doing some analysis on it. Is this something I should use .apply for?

Forgive me if this is a stupid question, but I'm really new to working with pandas and its slightly different from how a lot of python base types work.

Cingulate
Oct 23, 2012

by Fluffdaddy

Baby Babbeh posted:

What's the best way to go through a pandas dataframe and convert all of the values to a different value if they meet a set criteria? I've got a data frame representing grayscale images, where each cell is a value between 0 and 255, and I'd like to just convert this to black and white by changing anything that's not zero into a 1 prior to doing some analysis on it. Is this something I should use .apply for?

Forgive me if this is a stupid question, but I'm really new to working with pandas and its slightly different from how a lot of python base types work.
Just like in numpy?

df[df != 0] = 1

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



That... makes sense. I was overcomplicating this. It returns another df rather than changing it in place, right?

Cingulate
Oct 23, 2012

by Fluffdaddy

Baby Babbeh posted:

That... makes sense. I was overcomplicating this. It returns another df rather than changing it in place, right?
It assigns 1 to every place in the df whose former value is not 0. Nothing is "returned"; there is no function call.

indices = df != 0
df[indices] = 1

Seventh Arrow
Jan 26, 2005

A few questions:

1) What are some recommended books for python with big data/data analytics? (does not have to be specific to pyspark)

2) I'm still kind of new to programming and there's a lot of stuff to take in/remember. I assume that people usually don't just code things from scratch - do you keep cheat sheets around or what?

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Seventh Arrow posted:

2) I'm still kind of new to programming and there's a lot of stuff to take in/remember. I assume that people usually don't just code things from scratch - do you keep cheat sheets around or what?

This depends what you're doing - generally yes, you code things from scratch, but because there's a bit of 'boilerplate' (stuff you have to keep writing, like the __main__ function, or class definitions, etc) then you might want to create some templates. IDEs and fancy editors can often generate 'snippets' that are like smart templates for things where you can tab between the parts you need to fill in. That said, Python isn't as verbose as something like Java so there isn't as much need for it. Look at your IDE/editor and see what it offers! There's code completion too, much less typing for you

The other side of not coding things from scratch is using libraries - learning what's available and not reinventing the wheel. A lot of projects involve bolting together a few useful libraries and writing the code to do something with them. And again, if you keep making the same kinds of projects over and over (say a web server, or a twitter bot) you might want to create some skeleton projects with that basic setup already done, or a module that you can import with all that stuff in it

There can be more than that (applications that generate basic projects for you, or repositories you can basically clone and get building on top of) but it depends on the language

Best recommendation I can give you for remembering stuff is to get familiar with the docs. Whenever you find yourself wanting to do a thing (like manipulating a string in some way), go look at the docs for that type or module and see what methods and functions it offers. Even if you don't find something you need, you'll probably see some cool useful stuff. A lot of learning to program in a language is getting familiar with the standard library and what it can do for you

QuarkJets
Sep 8, 2008

I create functions for common code chunks that I either have reused before or know I will reuse later. For instance the file permission features that come bundled with Python are pretty simplistic, and at a time when I was working often with file permissions I wrote a little recursive chmod function. Now whenever I want to recursively change the permissions and ownership of a directory I just import that function.

If I've forgotten how something works I either google for it or just play around with it in a terminal. Say if I forgot whether os.walk iterated over (rootname, dirs, filenames) or (filenames, dirs, rootname); opening a Python session and invoking os.walk will show you right away what's going on. If I completely forgot that os.walk was even a thing then googling around should pull it up, since Python is an extremely popular language

QuarkJets fucked around with this message at 00:57 on Jun 9, 2017

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Seventh Arrow posted:

2) I'm still kind of new to programming and there's a lot of stuff to take in/remember. I assume that people usually don't just code things from scratch - do you keep cheat sheets around or what?

Kind of. I call it Google.

Seventh Arrow
Jan 26, 2005

Excellent, thanks for the answers!

FAT32 SHAMER
Aug 16, 2012



One day you too will reach the point where all the links in a google search for something are purple and you have to click through them to figure it out

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

One day you'll reach a point where all the Google results are for 3.x docs no you won't

Seventh Arrow
Jan 26, 2005

Well I'm still working my way through this book and I'm going to follow it up with this one, so I think I'll have my hands busy for a while. I'm also trying to learn Apache Spark , as if that weren't enough :toot:

accipter
Sep 12, 2003

baka kaba posted:

One day you'll reach a point where all the Google results are for 3.x docs no you won't

You can with py3redirect!

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell


oh gently caress yes

Adbot
ADBOT LOVES YOU

Eela6
May 25, 2007
Shredded Hen

:tviv:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply