This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Create development environment



Setting up the enviroment:

We are using vagrant for our development environments. You can find the instructions to get up and running here.

If for some reason you don't want to use vagrant or you prefer to not use a virtual machine, you can find the old setup instructions here.

Once you are done setting up, the virtual machine should already be running lernanta on port 8001. Create an account and login.

Communication:

You can communicate with other P2PU developers using this course or via our mailing list.

If you would like to be involved in other parts of the P2PU project, there are also the community mailing list.

Writing Task:

Then, let us know how it went below (or on your blog and link to that below). Run into any problems? How did you solve it? What worked well with the documentation and what didn't? What suggestions do you have for others starting to develop on Lernanta?

Task Discussion


  • Tim Gaudette said:

    updated virtual box to 4.2 because it has been a while since I used it

    installed vagrant

    cloned dev

    and up and running! quick and painless

    on Jan. 6, 2013, 4:43 p.m.
  • Satyakam Goswami said:

    using virtual env also the dev environment is working well

    on Dec. 3, 2012, 11:54 a.m.
  • Satyakam Goswami said:

    Why the dev list http://lists.p2pu.org/pipermail/p2pu-dev/ is not open , i tried posing a question regading irc , i could not find the room #p2pu-dev on freenode?

    on Dec. 3, 2012, 11:53 a.m.

    Dirk said:

    Hi Satyakam

    We typically moderate the first mail that anyone sends to the email list to stop spammers from telling us that we won the lottery :) After that your messages should go through immediately

    Cheers

    Dirk

    on Dec. 4, 2012, 8:34 a.m. in reply to Satyakam Goswami
  • Bo Z said:

    I havn't touched my dev environment for about 2 months now. I just synced the code on Monday and went through the setup steps following the document. However, I got stuck at Database creation. That is, when I ran 'make syncdb', I got the following error. Any ideas? Thank you. ( I removed some error messages in the middle to save page space. I can post them if anyone thinks it's necessary)


    Running migrations for djcelery:
     - Migrating forwards to 0002_initial.
     > djcelery:0002_initial
    Traceback (most recent call last):

    (...)

      File "/home/vampb/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 81, in run_migration
        migration_function()
      File "/home/vampb/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
        return (lambda: direction(orm))
      File "/home/vampb/.virtualenvs/lernanta/local/lib/python2.7/site-packages/djcelery/migrations/0002_initial.py", line 15, in forwards
        ('period', self.gf('django.db.models.fields.CharField')(max_length=24)),
      File "/home/vampb/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/db/generic.py", line 226, in create_table
        ', '.join([col for col in columns if col]),
      File "/home/vampb/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/db/generic.py", line 150, in execute
        cursor.execute(sql, params)
      File "/home/vampb/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
        return self.cursor.execute(sql, params)
    /django/db/backends/sqlite3/base.py", line 234, in execute
        return Database.Cursor.execute(self, query, params)
    django.db.utils.DatabaseError: table "djcelery_intervalschedule" already exists
    make: *** [syncdb] Error 1
     

    on June 20, 2012, 9:47 p.m.

    Dirk said:

    It's a little difficult to say exactly what went wrong, but try to update your requirments:

    pip install -r requirements/prod.txt

    Then wipe your database (remove/rename the sqlite file) and try to sync again. If you still get errors, post back here so that we can get to the bottom of it.

    Cheers

    d

    on June 21, 2012, 4:18 a.m. in reply to Bo Z

    Jos said:

    Hi there,

    have you tried the FORCE_DB option as explained in the cheat sheet?

    on June 21, 2012, 4:18 a.m. in reply to Bo Z

    Bo Z said:

    I just did. It skips syncing a bunch of apps. After that I can run the server, but as soon as I visit the website, I get a django error page saying "no such table: tracker_googleanalyticstracking". So I guess I still need syncdb to migrate fully?

    on June 21, 2012, 8:46 p.m. in reply to Jos

    Bo Z said:

    I removed the lernanta.db file and ran 'make syncdb' again. Got the same error message.

    on June 21, 2012, 9:11 p.m. in reply to Dirk

    Dirk said:

    I don't know exactly why that is happening? Are you working on the master branch from github.com/p2pu/lernanta?

    You can migrate the db for tracker only by running: "python manage.py migrate tracker"

    If this doesn't work, run 'python manage.py sql tracker' and post the output here. Then we can see wat tables should be generated. You can also inspect what is going on in the current db using "sqlite3 lernanta.db" and then running ".schema tracker_googeleanalyticstracking"

    I hope some of this helps :)

    on June 22, 2012, 6:12 a.m. in reply to Bo Z

    Bo Z said:

    Thanks for the tip. I managed to migrate all other apps than djcelery. I will just ignore that for now since I can probably get some work done without it.

    on June 23, 2012, 3:19 p.m. in reply to Dirk
  • Jessy Kate Schingler said:

    i used a clean-slate virtualenv with no site packages and just a dev (sqlite3) database. i had a few hiccups, the main one being around m2crypto. 

    • m2crypto hell: ubuntu doesn't compile sslv2 into the openssl package, so installing the vanilla python package for m2crypto via pip causes the error: 

    m2crypto.so: undefined symbol: SSLv2_method

    i dont quite understand why still, but if you apt-get install python-m2crypto and then copy the system package into the virtualenv manually (as suggested here), there is no error. i guess because the system package via apt is compiled with a recognition of this missing sslv2 support? anyway, it's better than hacking the m2crypto package code yourself. is there a better solution? action i took: 

    cp -r /usr/lib/python2.7/dist-packages/M2Crypto* ~/virtualenvs/lernanta/lib/python2.7/site-packages/ 

    (note the * to copy both the .egg file and the actual package) (and of course paths may be different on your system). 

    • PIL: if you're using a virtualenv with no site packages (the default in newer versions of virtualenv, as it should be!) then you definitely will need to install PIL locally in the virtualenv (along with other packages mentioned in troubleshooting section of  https://github.com/p2pu/lernanta/wiki/Lernanta%27s-Setup-Install)
    • need to create admin account credentials:
      • ./manage.py createsuperuser
    • would be great to include some demo data to get new devs started. creating test courses is a big hassle :p. 
    on June 10, 2012, 10:03 p.m.

    Dirk said:

    Hi Jessy

    I also tried the clean-slate virtualenv and ran into the same problems! I think I also had problems with MySQL-python?

    I don't know if the --no-site-packages are the answer. I like the idea, but I read around a bit and there seems to be some consenses that certain packages are best handled by your OS' package manager. [needs reference]

    There is some test data in lernanta/apps/badges/fixtures. I had trouble loading some of it whiile running mysql.

    Even though configuring mysql requires slighly more work, I think it's better running a dev enviroment closer related to production. At some stage we will need to invest some time into setting up a vagrant environment!

    Thanks for you feedback!

    d

    on June 11, 2012, 4:34 a.m. in reply to Jessy Kate Schingler

    Dirk said:

    on June 11, 2012, 4:58 a.m. in reply to Dirk
  • dany javier said:

    well the install documentation is really nice and clear. i don't have any problem, i followed the guide step by step.

    on May 27, 2012, 1:23 a.m.

    Dirk said:

    I noticed that you submitted a pull request on github! Thank you very much for your contribution!

    You can apply for the Open source contributor badge (https://p2pu.org/en/badges/p2pu-open-source-developer/) that applies to this challenge if you like!

    on June 1, 2012, 9:07 a.m. in reply to dany javier
  • Philipp said:

    I've got lernanta up and running (can start the server and access the home page).

    However, when I create a course, I get the following error message. Any help appreciated.

    TypeError at /groups/create/

     

     
    __init__() got an unexpected keyword argument 'parser'
     
    Request Method: POST
    Request URL: http://127.0.0.1:8000/en/groups/create/
    Django Version: 1.3
    Exception Type: TypeError
    Exception Value:
     
    on May 12, 2012, 9:55 a.m.

    Jos said:

    Hey Philipp, seems like your DB is out of sync with your code. Have you followed the tricks in the cheat sheet to keep the DB up to date? If you haven't, I would try to recreate the DB for tests:

     

    FORCE_DB=True python manage.py test

    and then try running the tests:

     

    python manage.py test

    If that all works, then you should be good to go.

    on May 12, 2012, 1:23 p.m. in reply to Philipp

    Philipp said:

    I'd try running the tests (with FORCE_DB=True) but get the same error for all tests:

     

    TypeError: __init__() got an unexpected keyword argument 'parser'
     
    It's been a while since I tried installing a webapplication and I might be missing something obvious. 
    on May 12, 2012, 3:52 p.m. in reply to Jos

    Dirk said:

    I don't think you are missing something obvious? We may need a little more data.

    On the terminal, go into the virtual enviroment:

    $ workon lernanta

    and then run:

    $ pip freeze | grep html5lib

    I get "html5lib==0.95"

    If you get something else, try to do a

    $ pip install html5lib==0.95

    and let us know if that resolves the issue?

    html5lib isn't listed in lernanta/requirements/prod.txt, so that may be the issue?

    on May 14, 2012, 4:19 a.m. in reply to Philipp

    Jos said:

    I've just updated my clone and it all works fine. I have the same version of html5lib so if it's not in the reqs files, then it 's probably being pulled in as a dependency.

    The two steps I did wre:

     

    pip install -r lernanta/lernanta/requirements/dev.txt

     

    python manage.py migrate --all --delete-ghost-migrations

    that worked for me. Also all tests run fine forcing the DB updagre. Let us know how you get on.

    on May 15, 2012, 8:45 a.m. in reply to Dirk

    Philipp said:

    Hey - Success!

    (1) I checked the lib5html version and it was up to date.

    (2) I ran the pip install and python manage.py migrate commands. pip re-downloaded a whole bunch of stuff and then installed a few of the dependencies, so apparently it hadn't completed installing them before. The migrate command actually looked like it had failed (i'll post the output below) but after running it I was able to start the server and can create a course without getting an error now. 

    Thanks abunch for all the help!

     

    (...)
    Running migrations for djcelery:
     - Migrating forwards to 0001_initial.
     > djcelery:0001_initial
    Traceback (most recent call last):
      File "manage.py", line 26, in <module>
        execute_manager(settings)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
        utility.execute()
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
        self.execute(*args, **options.__dict__)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
        output = self.handle(*args, **options)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/management/commands/migrate.py", line 105, in handle
        ignore_ghosts = ignore_ghosts,
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/__init__.py", line 191, in migrate_app
        success = migrator.migrate_many(target, workplan, database)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 221, in migrate_many
        result = migrator.__class__.migrate_many(migrator, target, migrations, database)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 292, in migrate_many
        result = self.migrate(migration, database)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 125, in migrate
        result = self.run(migration)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 99, in run
        return self.run_migration(migration)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/migration/migrators.py", line 82, in run_migration
        south.db.db.execute_deferred_sql()
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/db/generic.py", line 184, in execute_deferred_sql
        self.execute(sql)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/south/db/generic.py", line 150, in execute
        cursor.execute(sql, params)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
        return self.cursor.execute(sql, params)
      File "/home/l2p/.virtualenvs/lernanta/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
        return Database.Cursor.execute(self, query, params)
    django.db.utils.DatabaseError: index djcelery_periodictask_17d2d99d already exists
    on May 15, 2012, 2:19 p.m. in reply to Jos

    Jos said:

    Great stuff!

    both requirements files (dev and prod) should be watched for because if there is any change in them, then you will need to do the pip install step again. Have fun! :)

    on May 15, 2012, 2:39 p.m. in reply to Philipp
  • Prasanth said:

    Hello,

    I have managed to get lernanta running on localhost and also created an account and signed in. I would like to make two suggestions based on the experience:

    1.

    In the documentation at

    https://github.com/p2pu/lernanta/wiki/Lernanta%27s-Setup-Install

    we are asked to:

    " you can download the latest code or one of its past versions."
     

    I tried this with tag 1.5 but didn't work. Following Dirk's suggestion below, I tried the latest commit in repo, and it worked. 

    So perhaps the instructions should be modified?

    2.

    There is already a SECRET_KEY in settings.py, so is there a need for creating a new one?

    In any case, even with the latest commit in repo I get import error:

    $ ./manage.py shell

     

    In [1]: from django.utils.crypto import get_random_string
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    /home/phn/code/lernanta/lernanta/<ipython-input-1-c736522aaa3d> in <module>()
    ----> 1 from django.utils.crypto import get_random_string
     
    ImportError: cannot import name get_random_string
     

     

    Regards,

    Prasanth

     

     

     

     

    on April 20, 2012, 10:54 a.m.

    Jos said:

    Hi Prasanth, have you tried running the tests as explained in the cheat sheet. I just left a comment in the previous post to this one with a similar explanation. Not sure it will work but good to give it a go.

    on May 12, 2012, 1:25 p.m. in reply to Prasanth
  • Prasanth said:

    I followed the instructions at https://github.com/p2pu/lernanta/wiki/Lernanta%27s-Setup-Install.

     

    1. I downloaded the 1.5 tag of lernanta code repository.

    2. I couldn't generate SECRET_KEY:

     

     

    In [1]: from django.utils.crypto import get_random_string
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
     
    /home/phn/tmp/p2pu-lernanta-7077779/lernanta/<ipython console> in <module>()
     
    ImportError: cannot import name get_random_string
     
    Since there was already a SECRET_KEY in setting.py, I went ahead and ran
     
    make syncdb
     
    There were no error messages.
     
    3. I ran ./manage.py runserver. But got the following error when visiting http://127.0.0.1:8000/en/

     

    ViewDoesNotExist at /

    Could not import badges.views. Error was: cannot import name send_badges
    Request Method: GET
    Request URL: http://127.0.0.1:8000/en/
    Django Version: 1.3
    Exception Type: ViewDoesNotExist
    Exception Value:
    				Could not import badges.views. Error was: cannot import name send_badges
    Exception Location: /home/phn/lib/pyvirtualenv/lernanta/local/lib/python2.7/site-packages/django/core/urlresolvers.py in _get_callback, line 167
    Python Executable: /home/phn/lib/pyvirtualenv/lernanta/bin/python

     

    Am I making any obvious mistakes?

    on April 20, 2012, 7:04 a.m.

    Dirk said:

    Hi Prasanth

    Could you maybe try the latest version of Lernanta from github? I see the 1.5 tag is already 6 months old!

    Let us know if you still get errors?

    Regards

    Dirk

    on April 20, 2012, 7:11 a.m. in reply to Prasanth

    Prasanth said:

    Hello,

    The latest commit in the Github repo works.

    Thanks for the quick reply.

     

    Regards,

    Prasanth

    on April 20, 2012, 10:40 a.m. in reply to Dirk
  • Dirk said:

    Everything went perfect! Probably because of all the brave people breaking the ground before me!!

    One question: the two

    pip install
    

    commands took quite a while to complete ( more than 10 minutes each). Is this normal?

    on April 3, 2012, 7:43 a.m.

    Zuzel Vera said:

    it takes a while for me too, both the downloads and the actual install of the dependencies.

    on April 3, 2012, 9:20 a.m. in reply to Dirk
  • Corbin Tarrant said:

    I'm up to this point in the setup doc: 

    	.
    pip install -r lernanta/lernanta/requirements/prod.txt

    but I'm getting this:

    	.
    SWIG/_m2crypto.i:31: Error: Unable to find 'openssl/opensslv.h'
    
    
    SWIG/_m2crypto.i:45: Error: Unable to find 'openssl/safestack.h'
    
    
    SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
    
    
    SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
    
    
    error: command 'swig' failed with exit status 1
    on March 5, 2012, 2:40 a.m.

    Jos said:

    Hi Corbin, 

    which OS are you working on? if you are in ubuntu, could you check that the library libssl-dev is installed?

    apt get install libssl-dev

    should do the trick. In other linux distros the package might be called openssl-devel.

     

    Hope that helps!

    José

    on March 5, 2012, 3:49 a.m. in reply to Corbin Tarrant

    Corbin Tarrant said:

    I'm working on Ubuntu 10.04 and installing libssl-dev fixed the problem, thanks!

    on March 5, 2012, 2:11 p.m. in reply to Jos
  • Anonym said:

    Well, it's up and running now.

     

    There were some snags with the documentation, for example, a program named swig needed to be installed.

     

    In addition, PIL's Image module wasn't found at first, so I had to edit some files to change import Image to from PIL import Image. I had the latest version of PIL, so I'm not sure what the problem is. I posted a message to the p2pu-dev mailing list, and am waiting for a response.

    on Feb. 22, 2012, 2:51 p.m.
  • Jos said:

    Hi all, I found a really useful series of 5 minute long screencasts to understand what virtualenv and pip do, if like me, you are new to django. The first one is here, and you can find the other 4 parts in the same channel.

    cheers,

    José

    on Feb. 4, 2012, 10:44 a.m.

    Corbin Tarrant said:

    Thank you, these videos were helpful!

    on March 5, 2012, 2:44 a.m. in reply to Jos

    Corbin Tarrant said:

    I am a couple steps further now and trying to create the database but I am experiencing the same error a couple others (including yourself) have posted that they had below: "No module named Image"

    running

            pip install PIL --upgrade

    just tells me that "Requirement already up-to-date"

    on March 5, 2012, 2:23 p.m. in reply to Jos

    Jos said:

    Have you installed the "python-imaging" dependency?

    How did you create your environment? "mkvirtualenv lernanta" should allow you to use the python-imaging installed in your system. The old instructions used a --no-site-packages flag that should not be used anymore, or so I think!

    on March 5, 2012, 2:31 p.m. in reply to Corbin Tarrant

    Corbin Tarrant said:

    My system tells me that "python-imaging is already the newest version"

    I created my dev environment as specified in this document posted above.

    on March 5, 2012, 2:49 p.m. in reply to Jos

    Jos said:

    Apparently virtualenvwrapper changed flags in the latest version or so; could you try creating your environment with:

    mkvirtualenv lernante --system-site-packages

    That should allow access to your system PIL. Hope that works!

    on March 5, 2012, 3:01 p.m. in reply to Corbin Tarrant

    Corbin Tarrant said:

    That worked, the database has been created!

    Thanks again!

    My dev environment is all setup and I can start the server and connect to it. The process was a little bumpy and I think it would be helpful to add to the documentation some of the common problems discussed in these comments. I also think the short 5 part video series on python and virtualenv that were posted would be very helpful for people to watch, it was for me.

    on March 5, 2012, 4:07 p.m. in reply to Jos

    Jos said:

    Great stuff!

    Yeah, it was helpful for me too. I've been adding the steps to the doc as we were going along so I will add both the last bit (the flag) and the link to the videos. The wiki is open for editing so if you see anything missing feel free to add to it. :)

    cheers,

    José

    on March 5, 2012, 4:47 p.m. in reply to Corbin Tarrant
  • Anonym said:

    Just finished re-installing lernanta's instance so I can do some development on it!

    Some problems I encountered were...
    * I tried creating a bash script to export the virtual env variables, which I finally realised were completely losts due to the variables only being created while the script was running.
    *The Imaging bug when creating the db, apparently PIL needed a forced upgrade.
    * Having to install SWIG manually, and compile & find a missing dependency so that compiling would complete (PCRE).

    All this so I can update my Github with the lastest branch, phew.

    I'm not quite finished yet!  

    on Jan. 31, 2012, 12:52 a.m.
  • Vitor Pellegrino said:

    I ran into a pesky bug related to Ubuntu's Open SSL and python-m2crypto. I've covered the steps i went through to solve it in this blog post. 

    http://vp.blog.br/tip/2012/01/11/undefined-symbol-sslv2-method-in-ubuntu-11-10-and-12-04-alpha-1-installing-lernanta.html

    TL;DR 

    I had to use mkvirtualenv --system-site-packages lernanta instead of mkvirtualenv lernanta.  so my system would also look for system site packages, as Virtualenv changed its default behavior in 1.7. 

    I hope it helps other ubuntu users! 

    Thanks!

    on Jan. 10, 2012, 10:31 p.m.
  • Jos said:

    The documentation for Mac OSX here can be used with Lion.

    I did not install mysql or did another full install of python with homebrew (just used the default python with Lion which is 2.7.1)

    I did run into trouble with PIL (message was: ImportError: No module named Image). I fixed it by upgrading PIL from pip with: pip install PIL --upgrade

    on Nov. 26, 2011, 7:19 p.m.

    Jessica Ledbetter said:

    Great! Thank you.

    on Dec. 20, 2011, 1:35 p.m. in reply to Jos
  • Aaron V. said:

    I'm on Mac OS X 10.6, and I get "ImportError: No module named Image" when I try to run the "make syncdb" step

    on Nov. 15, 2011, 2:40 p.m.

    Jos said:

    Hi Aaron, I had the same problem and fixed it with:

    pip install PIL --upgrade

    cheers,

    Jos

    on Nov. 26, 2011, 6:37 p.m. in reply to Aaron V.
  • praveen said:

    Wow! installation was a breeze. The steps in the README worked flawlessely (Ubuntu 11.04)

    on Oct. 11, 2011, 1:01 p.m.

    Jessica Ledbetter said:

    Great to hear!

    on Oct. 12, 2011, 10:26 a.m. in reply to praveen
  • arturh said:

    I tried to install lernata on my mac without success. Some error about "mysql_config" not being there, although it was installed via MacPorts. I went the path of least resistance and got me a virtualbox instance with a minimal Ubuntu 11.04 server installation, followed instructions in README.rst (besides skipping setting up mysql, default configuration with mysql seems to work).

    on Sept. 1, 2011, 1:08 p.m.