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
NtotheTC
Dec 31, 2007


Tavistock posted:

Is this a good way of making entries only visible to their owners?

I feel as though there is a better way of handling it.

That's the way I do it, or well, I do:

Python code:
class SelfQueryMixin(object):

    def get_queryset(self):
        return self.request.user.model_set.all()  # The model related name
but that's just semantics. I'm not sure what the last part of the post means really. Are you talking about custom model managers?

NtotheTC fucked around with this message at 12:01 on Sep 16, 2013

Adbot
ADBOT LOVES YOU

MonkeyMaker
May 22, 2006

What's your poison, sir?
You can always make a model manager that takes a user argument.

code:
class OwnerOnlyManager(models.Manager):
    def owner(self, user=None):
        return self.get_queryset().filter(user=user)

Thermopyle
Jul 1, 2003

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

I really like django-model-utils PassThroughManager.
Python code:
class OwnerOnlyQuerySetMixin(QuerySet):
    def owned_by(self, user):
       return self.filter(user=user)

class SomeModel(models.Model):
    # some fields here
    objects = PassThroughManager.for_queryset_class(PostQuerySet)()
The problem with a regular Django Manager is that custom methods on it are unavailable on querysets returned by it. So, you can't do this with a regular Manager:

Python code:
a_queryset_of_some_model.owned_by(user=some_user).filter(created__gte=some_date)
That works when you're using PassThroughManager.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I've got an object that I need to access to all over the place, on every request. I've just been retrieving it as needed, but now when I look at my mysql query log I see the same query being executed 5 times within a single http request, obviously this is no good. I want it to be available like request.user is available, should I write a middleware component and stick this object on the request object?

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

I've got an object that I need to access to all over the place, on every request. I've just been retrieving it as needed, but now when I look at my mysql query log I see the same query being executed 5 times within a single http request, obviously this is no good. I want it to be available like request.user is available, should I write a middleware component and stick this object on the request object?

It'd make more sense to make it a context processor if you need it more in templates than in views. If you need it more in views, or equally in both, probably make a middleware.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Ok cool, thanks for the advice!

Got another one specific to Djangeo Rest Framework now that I'm looking at this query log.

I added a SlugRelatedField to one of my serializers and the number of queries it's executing shot up quite a bit. I tried to add select_related() to my get_queryset method, and now it uses an INNER JOIN to get one of the relationships. This particular model has a ForeignKey to self though, and it doesn't seem to want to use an INNER JOIN to get to that one, it just executes a bunch of individual queries. Any ideas what might be causing that behavior?

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

Ok cool, thanks for the advice!

Got another one specific to Djangeo Rest Framework now that I'm looking at this query log.

I added a SlugRelatedField to one of my serializers and the number of queries it's executing shot up quite a bit. I tried to add select_related() to my get_queryset method, and now it uses an INNER JOIN to get one of the relationships. This particular model has a ForeignKey to self though, and it doesn't seem to want to use an INNER JOIN to get to that one, it just executes a bunch of individual queries. Any ideas what might be causing that behavior?

IIRC, select_related() only works on forward-relationship FKs. Reverse-relationship FKs and ManyToManys require prefetch_related().

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Is there any way to get access to the request object when overriding the model save() method? I was thinking I'd create a base model that has fields like modified_by, modified_datetime, etc and automatically populate them in the save() method of this base model, but I don't seem to have access to the request object to determine the value for modified_by (which is a ForeignKey to a Player object, not User, if that matters).

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

Is there any way to get access to the request object when overriding the model save() method? I was thinking I'd create a base model that has fields like modified_by, modified_datetime, etc and automatically populate them in the save() method of this base model, but I don't seem to have access to the request object to determine the value for modified_by (which is a ForeignKey to a Player object, not User, if that matters).

Only by passing it in.

code:
my_model = MyModel({'data': data})
my_model.save(user=request.user)
and in the model:

code:
class MyModel(models.Model):
     def save(self, user, *args, **kwargs):
          self.modified_by = user
          super(MyModel, self).save(*args, **kwargs)
There might need to be a pop in there somewhere but it's the end of the day and I'm not thinking well.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I find myself creating nearly identical templates sometimes, one for Django and then one for Handlebars. Obviously this isn't ideal, since I have to maintain them in both places. I'm tempted to just use the Handlebars templates for all those cases, and simply render them in $(document).ready(). This has me wanting to be able to use my Django Rest Framework serializers in my Django templates, so the output of my Django template would just be a little placeholder element with a json object stuck in a data attribute or something, so it can be rendered using the Handlebars template client side. Is that possible? Is there some other way I should go about dealing with this?

Dominoes
Sep 20, 2007

I'm following the Getting Started With Django tutorial. I tried a few months ago, but gave up after vagrant/virtualbox/chef issues.

I'm trying again, but can't forgot how to do the SSH step. Using Windows. I've run vagrant.up, converted my insecure_private-key to a .ppk using Puttygen, run Putty per the instructions, and logged in as "vagrant" in Putty's terminal. I think I need to cd to my gswd vagrant directory I ran vagrant up in, but I don't know how to do it, since now I'm cding from a fake Ubuntu putty box. Any ideas? Vagrant up in the main (non putty) terminal seemed to work, which is promising.

On an experimental adventure: I tried typing vagrant ssh as the first command, and it prompted me to run sudo apt-get install vagrant. I did that, tried again, and was prompted to do vagrant init. Did that, tried again, and was told I have the wrong version of virtualbox and need 4.0 or 4.1. I'm not sure if it's referring to the version of vagrant I downloaded on my real computer, or the one apt-get installed. I tried uninstalling virtualbox and installing 4.1.26, but I get the same error. Do I need a specific version of 4.1? Overall, I'm just confused and am looking for instructions that leave nothing to the imagination.

Is it possible to dive in to Django without this extra stuff? It's frustrating and unrewarding - opposite of Python.

Dominoes fucked around with this message at 06:42 on Sep 30, 2013

Thermopyle
Jul 1, 2003

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

Dominoes posted:

I'm following the Getting Started With Django tutorial. I tried a few months ago, but gave up after vagrant/virtualbox/chef issues.

I'm trying again, but can't forgot how to do the SSH step. Using Windows. I've run vagrant.up, converted my insecure_private-key to a .ppk using Puttygen, run Putty per the instructions, and logged in as "vagrant" in Putty's terminal. I think I need to cd to my gswd vagrant directory I ran vagrant up in, but I don't know how to do it, since now I'm cding from a fake Ubuntu putty box. Any ideas? Vagrant up in the main (non putty) terminal seemed to work, which is promising.

On an experimental adventure: I tried typing vagrant ssh as the first command, and it prompted me to run sudo apt-get install vagrant. I did that, tried again, and was prompted to do vagrant init. Did that, tried again, and was told I have the wrong version of virtualbox and need 4.0 or 4.1. I'm not sure if it's referring to the version of vagrant I downloaded on my real computer, or the one apt-get installed. I tried uninstalling virtualbox and installing 4.1.26, but I get the same error. Do I need a specific version of 4.1? Overall, I'm just confused and am looking for instructions that leave nothing to the imagination.

Is it possible to dive in to Django without this extra stuff? It's frustrating and unrewarding - opposite of Python.

Try the official tutorial.

Dominoes
Sep 20, 2007

Did it a few months back, but couldn't hurt to do it again. ATM I'm reading ahead in GSWD to see if it's possible to work through it without the extra software.

Tavistock
Oct 30, 2010



What I ended up doing was ditching windows altogether (after getting fed up with all the strange byzantine workarounds I was doing) then not using vagrant at all to do Getting Started With Django. I was ramming my head against a wall trying to do all the stuff in windows when I noticed that everything I wanted to do seemed to be built for Linux/MacOS. The switch was super easy to Ubuntu and after a week I had everything filling comfortable.

This isn't answering your question but I think it might be worth your time to try switching to a unix-like. To answer your question I did just fine not using Vagrant but with the caveat of "I was using Ubuntu". If you have any questions or need help setting up Ubuntu hit me up at {myusername}91@gmail.com

Dominoes
Sep 20, 2007

Thanks dude - I think I'll take your advice and give it a shot on my Ubuntu laptop.

MonkeyMaker
May 22, 2006

What's your poison, sir?
As the creator of GSWD, yes, you can do it all without Vagrant and VirtualBox. I mostly provided the box so I wouldn't have to answer "how do I install Python, etc" on Windows.

Pollyanna
Mar 5, 2005

Milk's on them.


Is there an app for an interactive Python shell you can add to your website? I have an input string/file that I want to run a script on, and I want it to basically be a text box + converter similar to what this website does. Is there an option for this, or is there a better way to do it?

NtotheTC
Dec 31, 2007


Why do you need an entire interactive python shell embedded into your site to do a value conversion?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Don't embed Python into the web. It's just not meant for secure execution. Just learn JavaScript.

Pollyanna
Mar 5, 2005

Milk's on them.


The script as it is right now takes raw input (name of local file). The strings can be very long, so I'd like to give it the option of translating directly from that. I can have a text box too, of course.

In that case, do I just need to pass the string or filename into the script from the text box and have it output directly onto the webpage? Is there an object/model for accessing a Python script and returning the result?

Suspicious Dish posted:

Don't embed Python into the web. It's just not meant for secure execution. Just learn JavaScript.

What does secure execution mean in this case? It's mostly for personal use, so I don't think anyone will try and access my computer.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
By "secure execution" I mean "if you give somebody a Python prompt, even if you try really hard to sandbox it, they will always find a way to break through". And execute arbitrary code on your computer, and cause it to delete files, and steal all your porn.

Why, then, do you want it in a web page then, instead of just using Python on your local computer?

NtotheTC
Dec 31, 2007


Pollyanna posted:

Is there an object/model for accessing a Python script and returning the result?

Django is written in python, you can pass your input or file to django as a request and execute the script safely on the server-side, then return the output as a response.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Anybody else have performance problems with the built in development server running inside a virtual machine? I've got Windows 7 for my host OS, Linux Mint 15 for my guest OS. When I hit a URL for my app using Firefox on Windows, it takes 20 seconds to load. Hitting the same URL with Firefox from inside the VM takes about 3 seconds to load. It is excruciating watching my CSS styles being applied rule by rule! Same crap performance using Chrome on the host OS. I suppose I could just use the browser in my VM all the time, but figured I might as well ask in case anybody else has run into this and knew how to fix it.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
You might not have the correct virtualization flags set in your BIOS. They can make a huge difference to performance, and also allow you to run 64bit VMs. I would check that before troubleshooting other stuff.

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

Anybody else have performance problems with the built in development server running inside a virtual machine? I've got Windows 7 for my host OS, Linux Mint 15 for my guest OS. When I hit a URL for my app using Firefox on Windows, it takes 20 seconds to load. Hitting the same URL with Firefox from inside the VM takes about 3 seconds to load. It is excruciating watching my CSS styles being applied rule by rule! Same crap performance using Chrome on the host OS. I suppose I could just use the browser in my VM all the time, but figured I might as well ask in case anybody else has run into this and knew how to fix it.

I run an Ubuntu VM in a Vagrant on my Mac and don't have speed issues anywhere near that long. Maybe a few extra milliseconds.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Maluco Marinero posted:

You might not have the correct virtualization flags set in your BIOS. They can make a huge difference to performance, and also allow you to run 64bit VMs. I would check that before troubleshooting other stuff.

Went through and double checked all that stuff, seemed to look ok. Virtualization options enabled in the BIOS, IO APIC enabled, 4GB RAM allocated, 4 CPU cores, PAE/NX enabled, VT-x/AMD-V enabled, use host i/o cache, solid-state drive checked. Performance in the VM itself seems excellent, just the network performance from host to guest seems to suffer. I wonder if it's because I'm using NAT?

As a test, I did a wget from the host OS to a 10MB file being served by runserver. Took a couple seconds to start and then transferred at 2MB/s.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm trying to run ./manage.py test but I get:

quote:

DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes')

I'm using MySQL, and the default charset is set to utf8mb4. From looking at the MySQL log, the test runner appears to be attempting to create the following table:
code:
CREATE TABLE `auth_customuser` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `password` varchar(128) NOT NULL,
    `last_login` datetime NOT NULL,
    `email` varchar(255) NOT NULL UNIQUE,
    `is_active` bool NOT NULL,
    `is_admin` bool NOT NULL,
    `date_of_birth` date NOT NULL
)
I understand why the email field causes this error, but why is the test runner even creating this table in the first place? It doesn't exist in my app normally.

edit: oh and I tried setting TEST_CHARSET to latin1 in my settings.py, but that didn't seem to do anything? I don't want to use latin1 for my tests anyways but I thought that would allow me to temporarily get around this issue...

fletcher fucked around with this message at 00:37 on Oct 16, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Of course I go weeks of putting up with that VM performance problem and it magically goes away hours after I decide to finally bitch about it. Seems nice and snappy now :shrug:

Pollyanna
Mar 5, 2005

Milk's on them.


I'm trying to push Django onto Heroku. When I run git push heroku master, I get this error:

code:
Warning: Permanently added the RSA host key for IP address '50.19.85.156' to the list of known hosts.
Counting objects: 21, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (17/17), done.
Writing objects: 100% (21/21), 7.04 KiB, done.
Total 21 (delta 0), reused 0 (delta 0)

-----> Removing .DS_Store files
-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Preparing Python runtime (python-2.7.4)
-----> Installing Distribute (0.6.36)
-----> Installing Pip (1.3.1)
-----> Installing dependencies using Pip (1.3.1)
       Downloading/unpacking Cython==0.19.1 (from -r requirements.txt (line 1))
         Running setup.py egg_info for package Cython
           Compiling module Cython.Plex.Scanners ...
           Compiling module Cython.Plex.Actions ...
           Compiling module Cython.Compiler.Lexicon ...
           Compiling module Cython.Compiler.Scanning ...
           Compiling module Cython.Compiler.Parsing ...
           Compiling module Cython.Compiler.Visitor ...
           Compiling module Cython.Compiler.FlowControl ...
           Compiling module Cython.Compiler.Code ...
           Compiling module Cython.Runtime.refnanny ...
           
           warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
           warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
           warning: no files found matching '*.h' under directory 'Cython/Debugger/Tests'
           warning: no files found matching '*.pxd' under directory 'Cython/Utility'
       Downloading/unpacking Django==1.5.4 (from -r requirements.txt (line 2))
         Running setup.py egg_info for package Django
           
       Downloading/unpacking PIL==1.1.7 (from -r requirements.txt (line 3))
         Running setup.py egg_info for package PIL
           WARNING: '' not a valid package name; please use only.-separated package names in setup.py
           
       Downloading/unpacking QSTK==0.2.6 (from -r requirements.txt (line 4))
         Running setup.py egg_info for package QSTK
           
           WARNING: QSTK is a namespace package, but its __init__.py does
           not declare_namespace(); setuptools 0.7 will REQUIRE this!
           (See the setuptools manual under "Namespace Packages" for details.)
           
           warning: no files found matching '*' under directory 'bin'
           warning: manifest_maker: MANIFEST.in, line 8: 'recursive-include' expects <dir> <pattern1> <pattern2> ...
           
           warning: manifest_maker: MANIFEST.in, line 9: 'recursive-include' expects <dir> <pattern1> <pattern2> ...
           
           warning: no files found matching '*' under directory 'QSData'
           warning: no files found matching 'QSTK/QSData/Yahoo/*.csv''
       Downloading/unpacking TA-Lib==0.4.7 (from -r requirements.txt (line 5))
         Running setup.py egg_info for package TA-Lib
           Traceback (most recent call last):
             File "<string>", line 16, in <module>
             File "/tmp/pip-build-u20493/TA-Lib/setup.py", line 3, in <module>
               from Cython.Distutils import build_ext
           ImportError: No module named Cython.Distutils
           Complete output from command python setup.py egg_info:
           Traceback (most recent call last):
       
         File "<string>", line 16, in <module>
       
         File "/tmp/pip-build-u20493/TA-Lib/setup.py", line 3, in <module>
       
           from Cython.Distutils import build_ext
       
       ImportError: No module named Cython.Distutils
       
       ----------------------------------------
       Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-u20493/TA-Lib
       Storing complete log in /app/.pip/pip.log

 !     Push rejected, failed to compile Python app

To git@heroku.com:damp-dawn-2192.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:damp-dawn-2192.git
This is my requirements.txt:

code:
Django==1.5.1
dj-database-url==0.2.1
dj-static==0.0.5
gunicorn==17.5
psycopg2==2.5.1
static==0.4
Why is it trying to install all that extra crap? It's not specified anywhere in the file. Is it using a different requirements.txt or something? I'm running inside a virtual environment and the same directory, if that matters.

EDIT: Never mind, blame Git.

edit2: In fact, I'm gonna ask about deploying Django. I know that Heroku seems to be fairly popular, but I've found that deploying Django to it is kind of a pain. What's the best service to use?

Pollyanna fucked around with this message at 21:11 on Oct 18, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
If I leave a field blank, I get a nice little This field is required. error message. If I put whitespace in there, it gets around the standard validation and does not throw that same error message.

Some googling led me to this ticket where they concluded that is how the behavior will remain. I can't quite figure out how to implement that behavior myself though. I ended up with something like this:

code:
class Whatever(models.Model):
    awesome_field = models.CharField(max_length=100)

    def clean(self):
        strip_fields = [ 'awesome_field' ]

        for field in strip_fields:
            if getattr(self, field) is not None:
                setattr(self, field, getattr(self, field).strip())
It seems to strip the whitespace...but it's not throwing the This field is required. message like I thought it would. What am I doing wrong?

Thermopyle
Jul 1, 2003

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

Pollyanna posted:

edit2: In fact, I'm gonna ask about deploying Django. I know that Heroku seems to be fairly popular, but I've found that deploying Django to it is kind of a pain. What's the best service to use?

You're doing something wrong. Deploying Django to Heroku is super easy.


fletcher posted:

If I leave a field blank, I get a nice little This field is required. error message. If I put whitespace in there, it gets around the standard validation and does not throw that same error message.

Some googling led me to this ticket where they concluded that is how the behavior will remain. I can't quite figure out how to implement that behavior myself though. I ended up with something like this:

code:
class Whatever(models.Model):
    awesome_field = models.CharField(max_length=100)

    def clean(self):
        strip_fields = [ 'awesome_field' ]

        for field in strip_fields:
            if getattr(self, field) is not None:
                setattr(self, field, getattr(self, field).strip())
It seems to strip the whitespace...but it's not throwing the This field is required. message like I thought it would. What am I doing wrong?

I'm a little confused about what you're trying to do. Can you not use blank=True, null=True on the field?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Thermopyle posted:

I'm a little confused about what you're trying to do. Can you not use blank=True, null=True on the field?

I have a field that is required, so I want blank=False, null=False. If you enter only whitespace as the value, it gets around the validation. So I just want to strip the whitespace from the value they enter, and if all they entered was whitespace, I want it to say "This field is required." without having to write the validation message myself.

Pollyanna
Mar 5, 2005

Milk's on them.


Thermopyle posted:

You're doing something wrong. Deploying Django to Heroku is super easy.

That may be the case. I guess I'll try again once I get more familiar with Django.

Speaking of, forgive me for asking yet more questions, but I'm kind of bewildered by something I want to do. After going through the demo on the Django site (the one about making polls), I've decided that I want a homepage to be displayed when you go to localhost:8000. However, I haven't written a webpage in over 13 years and the last time I did, it was hand-typed in HTML. The way Django structures itself, a single subdirectory ("app") contains files that somehow make a webpage/.html, and apparently it's a bad idea to put any models.py or views.py scripts in the root folder. Assuming that the /polls subdirectory is equivalent to localhost:8000/polls/, shouldn't I be able to put an HTML page at localhost:8000/ ? Django generally works by creating "apps" within a project, though, and I don't understand how an "app" would create a homepage.

Maybe I'm just way out of date on my web development, but this doesn't make much sense to me.

Thermopyle
Jul 1, 2003

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

Pollyanna posted:

That may be the case. I guess I'll try again once I get more familiar with Django.

Speaking of, forgive me for asking yet more questions, but I'm kind of bewildered by something I want to do. After going through the demo on the Django site (the one about making polls), I've decided that I want a homepage to be displayed when you go to localhost:8000. However, I haven't written a webpage in over 13 years and the last time I did, it was hand-typed in HTML. The way Django structures itself, a single subdirectory ("app") contains files that somehow make a webpage/.html, and apparently it's a bad idea to put any models.py or views.py scripts in the root folder. Assuming that the /polls subdirectory is equivalent to localhost:8000/polls/, shouldn't I be able to put an HTML page at localhost:8000/ ? Django generally works by creating "apps" within a project, though, and I don't understand how an "app" would create a homepage.

Maybe I'm just way out of date on my web development, but this doesn't make much sense to me.

The url you visit has nothing to do with the filesystem path.

When you visit an url like the root url, Django looks in urls.py to determine which view to render. You create a view in views.py. That view passes smashes data into a template that you can really put wherever you want, however there are conventions for template locations. If it's a template for an app, class-based views expect it in app/templates/app/.

So, what you see when you visit localhost/ or localhost/butts or localhost/foo is determined by urls.py selecting a view out of views.py which selects a template out of wherever you configure the view to look. Hell, you can have all of the urls point to the same view.

Pollyanna
Mar 5, 2005

Milk's on them.


Goes to show that I have a lot more to learn.

I have a new error: now I get "ImportError: No module named _collections". It was literally working just a second ago, but then I tried to runserver and now it's dying on me.

:cry:

edit: I can't even run help() in the Python shell. :psyduck: What the hell happened?

Pollyanna fucked around with this message at 01:51 on Oct 19, 2013

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

Pollyanna posted:

Goes to show that I have a lot more to learn.

I have a new error: now I get "ImportError: No module named _collections". It was literally working just a second ago, but then I tried to runserver and now it's dying on me.

:cry:

edit: I can't even run help() in the Python shell. :psyduck: What the hell happened?

What operating system are you working in?

Also, I saw that you said you were using virtualenv, make sure that is working properly. You could be calling a different/nonexistant python installation.

Pollyanna
Mar 5, 2005

Milk's on them.


The March Hare posted:

What operating system are you working in?

Also, I saw that you said you were using virtualenv, make sure that is working properly. You could be calling a different/nonexistant python installation.

Um, I'm on OSX. I actually decided to scrap the whole project and start again, which involved deleting the "venv" folder...I think that's what hosed me up. :ohdear: You said that it should be working properly/calling a nonexistent python installation, and I think that's what's happening maybe. How do I fix it?

What's worse, here's what happens when I try to run virtualenv:

code:
$ virtualenv
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv", line 5, in <module>
    from pkg_resources import load_entry_point
zipimport.ZipImportError: can't decompress data; zlib not available

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

Pollyanna posted:

Um, I'm on OSX. I actually decided to scrap the whole project and start again, which involved deleting the "venv" folder...I think that's what hosed me up. :ohdear: You said that it should be working properly/calling a nonexistent python installation, and I think that's what's happening maybe. How do I fix it?

What's worse, here's what happens when I try to run virtualenv:

code:
$ virtualenv
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv", line 5, in <module>
    from pkg_resources import load_entry_point
zipimport.ZipImportError: can't decompress data; zlib not available

Type 'which python' into the terminal. If you aren't in a virtualenv it should say something like /usr/bin/python on osx, that would mean that all of your python stuff is coming out of the default system-wide python installation on osx. I suspect your terminal session is still in the virtualenv that you have now deleted, and so it is trying to do all of these things using installations of python and easy_install and whatever else but cannot, because all of the files that do those things are missing because you deleted them. When you run source bin/activate like the virtualenv tutorial tells you to it changes where your system looks for python and such to that directory (which was created by virtualenv, and which contains isolated installs of python and other things), instead of the default system install.

Try typing 'deactivate' and then doing whatever else, should turn off the virtualenv session if you are in one. (By turn off I mean it will reset your path to the system default, which you almost certainly have not deleted, which will then allow you to do things again.)

The March Hare fucked around with this message at 03:03 on Oct 19, 2013

Pollyanna
Mar 5, 2005

Milk's on them.


code:
Rebeccas-MacBook-Pro:~ rebecca$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Rebeccas-MacBook-Pro:~ rebecca$ deactivate
-bash: deactivate: command not found
Rebeccas-MacBook-Pro:~ rebecca$ python -c 'help("modules")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 454, in __call__
    import pydoc
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 55, in <module>
    import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 41, in <module>
    from operator import attrgetter
ImportError: No module named operator
Rebeccas-MacBook-Pro:~ rebecca$
:saddowns:

Adbot
ADBOT LOVES YOU

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

Pollyanna posted:

code:
Rebeccas-MacBook-Pro:~ rebecca$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Rebeccas-MacBook-Pro:~ rebecca$ deactivate
-bash: deactivate: command not found
Rebeccas-MacBook-Pro:~ rebecca$ python -c 'help("modules")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 454, in __call__
    import pydoc
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 55, in <module>
    import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 41, in <module>
    from operator import attrgetter
ImportError: No module named operator
Rebeccas-MacBook-Pro:~ rebecca$
:saddowns:

Erghhh, can you paste the response from echo $PATH because I have no idea what is going on.

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