On Wed, Nov 21, 2012 at 8:58 AM, Luisa Beck <emmi.b...@gmail.com> wrote:

> Thank you for your thoughts! I have a few follow-up questions:
>
> *The reason that I’m trying to figure out postgres is that I’m helping
> some folks with a development project and they’re using postgres. I’m
> trying to do the tutorial with that so that I can get familiar with
> postgres and the pgAdmin III interface. And also with how Django, Python
> and Postgres work together (your explanation has been very helpful with
> that).
>
> Regarding your explanations:
>
> I have a bash “Terminal” and an SQL Shell. I also have virtual
> environments in a folder ~/Sites/django_test (i.e. when I tell the bash
> Terminal to “activate” this folder, it puts me in a an (env)).
> However ,when I run “python manage.py runserver" at the bash Terminal
> command line, I get an error message saying “can't open file 'manage.py':
> [Errno 2] No such file or directory”. *
>

When you run a manage.py command, you must do it when the shell's current
directory is the one containing the manage.py file of your django project.
Use the shell command "pwd" to see what directory is current.  Use "ls" to
see what files are in that directory.  Use "cd some/path" to make the
current directory "some/path".  Paths can be absolute, meaning the begin
with the "/" character (slash, solidus, bar sinister), or they can be
relative to the current directory, e.g.; if the current directory is
"/home/luisa" (sorry, I don't remember what Mac home directory paths look
like), then "cd some/path" will Change the current Directory to
"/home/luisa/some/path".  You can use "../" to go up the directory tree,
e.g.; if the current directory is "/home/luisa/some/path" then "cd
../../venvs/myproject/bin" will make the current directory be
"/home/luisa/venvs/myproject/bin".  Note that your home directory is
sometimes shown by the shortcut "~" (which you can also use on input, so a
"pwd" (print working directory) after the last command might print
"~/venvs/myproject/bin".

If, as Thomas suggests, your virtualenv is actually broken, please note
that you can't copy or move virtualenvs around.  But they are, indeed,
blessedly easy to create, so long as you have network access (since you
will have to re-install the packages).  You can create a requirements.txt
file from the old virtualenv, while it is active (and you should to this
and put the result in your revision control system for the project so that
it can be easily recreated) by typing "pip freeze > requirements.txt".
(You can use another name than requirements.txt, but this is traditional,
so that others will know what it is.)  Then, when you have created and
activated the new virtualenv, type "pip install -r requirements.txt", and
all the stuff will get re-installed.

> *
> Even when I run the command in the (env), I get the error message:
> /Library/Frameworks/Python.framework/Versions/3.2/Resources/Python.app/Contents/MacOS/Python:
> can't open file 'manage.py': [Errno 2] No such file or directory      (Which
> I presume is telling me that the path is still set on an incorrect version
> of Python (3.2), even though I want to use version 2.7 and trashed the 3.2
> version from my system. )*
>

When you created the virtualenv, did you use "-p python2.7" on the
virtualenv command line?  Otherwise virtualenv will use whatever python is
default.  It should be perfectly fine to have multiple versions of python
installed at the same time.  On some systems, it is also dangerous to
"trash" the default python, since system maintenance stuff is often written
in python, and may be version sensitive (this is particularly true on
linux).  Make sure that you cann start python2.7 by typing "python2.7" at
the shell and confirm that the banner it prints says that it is a
2.7.something version.  That has to work before you make the virtualenv.

> *
>
> I think that there are a few gaps in my understanding here:
>
>    - I don’t understand the difference between typing in commands into my
>    bash Terminal versus my SQL shell
>
> *
>
bash is a tool for running commands on your computer.  The first "word" of
a bash command line is the name of a command or program.  If you type "less
~/myproject/manage.py" you are asking bash to run the "less" program, which
interprets "~/myproject/manage.py" as the path to a file that you want to
display in that terminal window.  If it were a big file, less would show it
a page at a time, and you would type spaces, which will go to less rather
than bash, because less is the "foreground" job, to go to the next page.
You will want to know that "q" is the command to exit from less, after
which you would be talking to bash again.

I'm guessing that your SQL shell is a tool that takes what you type and
sends it off to the database's port, plus a few things executed within the
SQL shell program itself, like specifying which database to use, or asking
it to print help text.


> *
>
>    - Is running “python manage.py runserver” the same as running Python
>    programs with an IDE like IDLE?
>
> *
>
It is probably best not to think of it that way.  While it may be possible
to run manage.py from an IDE (and some are set up to help with Django in
this way), things aren't quite the same.  For one thing, you may have
trouble figuring out how to pass "runserver" as a "command line argument".
If you have an IDE specifically designed (and configured) for debugging
Django, it will have its own set of instructions for running stuff.

When you say "python manage.py runserver", you are telling bash to run
"python" (whichever on it finds first on the PATH) and to pass it two
command line arguments, "manage.py" and "runserver".  Python expects the
first of these (since it does not begin with "-") to be the name of a file
in the current working directory (or the path to such a file), which it is
to load (like with import).  Python first "adjusts" things so that it
appears that when the code invoked by manage.py asks what the first command
line argument is, it sees "runserver".  I might be able to figure out how
to fake that from IDLE, but I haven't found the need.


> *
>
>    - How and where do I adjust your $PATH environment variable so that
>    the correct python occurs first on the path?
>
> *
>
Activating the virtualenv, if you're using one, adjusts $PATH for you.  If
you are instead looking to have a path addition in some shell without using
a virtualenv, you can use the bash command:

    export PATH="/foo/bar:/ugh/bletch:$PATH"

To add "/foo/bar" and "/ugh/bletch" before all the stuff already on $PATH.
If you wanted to have this happen every time you start a shell, you would
put the command above in a file in your home directory named ".profile" or
".bash_profile", the naming varies, and I'm not sure how it is done on the
Mac.


> *
>
>    - I think that I installed the correct Python version into the virtual
>    environment using pip install. Why am I still receiving a “No such file or
>    directory” error?
>
> *
>
You don't use pip to install python.  You use the -p flag to virtualenv to
tell which existing python to use.  Not finding manage.py is unrelated to
which python is being used, as discussed above.  A normal sequence might be:

    mkdir -p ~/venvs
    cd ~/venvs
    virtualenv -p python2.7 --distribute --no-site-packages djproject
    source djproject/bin/activate
    pip install django
    mkdir -p ~/src
    cd ~/src
    django-admin.py startproject djproject
    cd djproject
    ln -s ~/venvs/djproject/bin/activate .
(That last line is one I like to make it easier to activate the correct
virtualenv at the start of the day.  I cd to the correct directory and say
"source activate".  If I have multiple projects with different virtualenvs,
I don't have to think about which virtualenv goes with the project I'm
about to work on.)
Now the current directory contains a file named "manage.py", as "ls" will
show.  You have clearly done some of this if you're following the tutorial,
but the tutorial doesn't use virtualenv, so things are a bit different.
I'd suggest that you start with the above, then copy in any settings.py,
urls.py, etc., that you have already worked on.

*
>
>    - Why does Python version 3.2 still appear in the path indicated by my
>    error message is I trashed it?
>
> *
>
Since I don't know what you mean by "trashed" and I don't really have a
handle on the different from other *nixes directory layout of the Mac, nor
its packaging, I can't really help you here.  All the boxes I use are happy
to have more than one python installed, but you can only get at one of them
using just "python".  If you want a different one, use it's version (just
major and minor) appended to the name, such as "python2.7" or "python3.2".
These all exist as files in directories on the path when they are all
installed.  One of them has an alias (actually link or symbolic link) by
the name "python".

There *can* be another "python" in another directory on the path, but the
first one found wins.  You could get to such using a full absolute path.
For example, if /usr/bin occurs before /usr/local/bin on the path (you can
tell bash "echo $PATH" to see), and they both have a program named
"python", you could get to the second by, instead of starting a bash
command with just "python", start it with "/usr/local/bin/python".

> *
> If you could help me with these questions, or simply list links with any
> tutorials that explain this, that would be much appreciated. Or perhaps you
> know how I can access ‘freenode’ so that I can ask in the discussion forum?
> Thanks!*
>
All I know is that you need an IRC client (chatzilla is a plug in for
firefox, I think), and that you need to "identify" to the server.  I don't
really use it myself.

>
>
> Also, I'm having trouble entering freenode because it says that " #Django 
> Cannot
>>> join channel (+r) - you need to be identified with services"
>>>
>>> And lastly, if someone could forward me a tutorial about how the
>>> databases, python files,
>>> virtual environments and Django work together (I am new to all of these)
>>> that would be much appreciated!
>>>
>>> Thanks in advance!
>>> Luisa
>>>
>>>
>>> I'm no Mac expert, but I'll offer a couple of thoughts.
>>
>> First, you shouldn't need to solve both the PostgreSQL installation issue
>> and learning Django at the same time.  sqlite3 is adequate to the tutorial,
>> and is built in to modern pythons (e.g.; 2.7), and I presume that's true on
>> the Mac as well.
>>
>> Django is written in Python, which requires no pre-compilation, but must
>> be run with a python interpreter, e.g.; "python manage.py runserver" at the
>> command line.  The tutorial is written with the assumption that you will be
>> running it from the command line.  If you have more than one python
>> installed on your system, you can specify which one to use by including the
>> path on the command line, such as "~/bin/python manage.py runserver", or
>> you can adjust your $PATH environment variable so that the correct python
>> occurs first on the path.  This last is what virtualenv does: the activate
>> code (which you must "source", not run, e.g.; "source
>> ~/venvs/djtutorial/bin/**activate") adjusts the PATH (and prompt) of the
>> shell that sources it so that the virtualenv's python is found first*, and
>> defines a "deactivate" shell function that will undo the changes (exiting
>> the shell is just as good - i.e., this will not last across a reboot, you
>> must activate each new shell - command line window - that you start to work
>> on this project).  Python figures out where you ran it from, and searches
>> from there for it's libraries, and finds first those associated with the
>> virtualenv, e.g. "~/venvs/djtutorial/lib/**python2.7/".  This means that
>> you can install things there (e.g.; by using "pip install ..." from a shell
>> that has been activated for that virtualenv) and they won't effect your
>> base python installation.
>>
>> [ * Perhaps not commonly understood, you don't need to activate if you
>> specify the path to the correct python, e.g.;
>> "~/venvs/djtutorial/bin/python manage.py runserver", so it is easy to
>> create a shell script or even an alias that does your most common stuff.
>> For example, you might make a copy of manage.py, maybe called "manage", add
>> a first line with the magic incantation:
>>
>> #!/absolute/path/to/the/**correct/python
>>
>> Then make that file executable ("chmod a+x manage") and you will be able
>> to do "./manage runserver", etc., whether or not you have activated in the
>> current shell.  (I specifically recommend against putting the project
>> directory on your path, thus the "./" part.) ]
>>
>> For most databases Django connects to the database's socket to
>> communicate.  For sqlite3 the code is running within your python
>> interpreter and it reads and writes the specified file for persistence.
>> Django's ORM maps models onto database tables and the fields of the model
>> onto the columns of the table, and provides the "syncdb" command for
>> initializing the tables.
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Any7ms_MjRMJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to