|
I've been through the Webfaction 'Getting Started with Django' instructions which were very clear and make sense. However, I have an existing Django project I wish to use, and I'd like to run it within a virtualenv and I'm not sure how to amend those instructions for running the server within a virtualenv. I have virtualenv running OK on the command line, but hit problems when trying to access my Django site. I've read these instructions which helped me get this far (using a standard Django app, as per the above instructions, rather than a mod_wsgi one), but Django seems confused about project and app names, and I'm stuck. Does anyone have simple instructions, to continue from Webfaction's Django instructions, about using virtualenv? |
|
Virtualenv has experienced some changes since this question was originally written. Also, some people like to remove the packages in
Now that virtualenv and virtualenvwrapper are installed, you can create, activate, deactivate, and remove environments:
This virtualenv will not use the global site packages in However, because of the global In some cases this is what you want and is convenient. Other times, you do not want a particular virtualenv to use your home-installed packages. If that's the case, then create an empty
and then this virtualenv (" This rocks! Thanks Ryan!!! :) WOW. This worked perfectly. THANK YOU. I'm marking this as the accepted answer because the others are outdated now and causing some confusion. |
|
Oh, thanks David. I found a couple of crucial wsgi configuration lines in there that eventually got my site working! For future visitors, below is a summary of everything I've done to get things working. If anyone has any suggestions about things to improve, do let me know, as I've only worked this out by trial and error. This assumes you've probably used pip and virtualenv/virtualenvwrapper before and just want to get it working on WebFaction. Follow the 'Getting Started with Django' instructions for setting up a Django site. This will have created:
Then:
Add these lines at the end of .bashrc:
Then:
Obviously, with a meaningful name instead of 'my_env_name'. Now we're working within that virtual environment. Install any things you need. eg:
Or install from a pip requirements file from an existing project:
Then edit ~/webapps/django_application/myproject.wsgi. I don't know if all of these are required, but it seems to work for me...
Obviously, replace 'username', 'my_env_name', 'django_application' and 'myproject' as appropriate. Finally:
You'll need to do that last line every time you make a change to myproject.wsgi. thanks for these instructions. I had to make just a couple of changes to use python2.7: mkvirtualenv --no-site-packages --distribute --python=/usr/local/bin/python2.7 my_env_name site.addsitedir('/home/username/.virtualenvs/my_env_name/lib/python2.7/site-packages') Hi, sorry for coming back to this post but I have a question. I have a running installation in production. Instead of installing the django modules (e.g. dango-avatar) again, can't I just copy them or use them from my existing installation? I have made some slight modification in some modules to work with django 1.4 and I am not sure if I want to risk it and redo those changes while in production mode. Hi, As long as make sure the path where they're copied is consistent with the Python search path in your virtualenv, you should be able to just copy them. Thank you. One last question. Do I need to completely shut down the server while doing this procedure? Or as long as everything is done according to the tutorial above the restart at the end is enough? Hi again, Yes, you can just restart at the end, and it should be ok. If you experience any issues, feel free to open a ticket. Thank you. I will try first by myself, and see what I can do :-). Just one more question. Do I need to install Django 1.4, too, to my new virtualenv? You probably want to do that, as it's the point of using a virtualenv. Just putting Django1.4 somewhere on the Python search path would also do though. because I had pip aliased to /home/xpanta/bin/pip I accidentally installed Django 1.4 on my home path (/home/xpanta/lib/python2.7/). I actually wanted to install in my virtual-env. What should I do now? I tried to install it my virtual-env and I get "Requirement already satisfied (use --upgrade to upgrade): Django in /home/xpanta/lib/python2.7" You can run If, for some reason, Once django is gone, Hope that helps! Isn't that dangerous for my other django projects that are not in virtualenvs? (btw, pip install remove did not work)
1
It shouldn't be dangerous, but it could be. Specifically, Django applications when set up via a one-click installer use a separate Django installed in However, if you have set up Django applications to use this library specifically, then yes, it would be dangerous. I'm getting this error when I try installing the virtualenvwrapper: $ pip install virtualenvwrapper Traceback (most recent call last): File "/home/vegan/bin/pip", line 7, in ? sys.exit( File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 277, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2180, in load_entry_point return ep.load() File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 1913, in load entry = import(self.module_name, globals(),globals(), ['name']) File "/home/vegan/lib/python2.4/pip-1.2.1-py2.4.egg/pip/init.py", line 9, in ? from pip.basecommand import command_dict, load_command, load_all_commands, command_names File "/home/vegan/lib/python2.4/pip-1.2.1-py2.4.egg/pip/basecommand.py", line 4, in ? from pkgutil import walk_packages Please open a ticket at our support site, and we'll help you find the cause of the issue. the lines
in the wsgi.py file are the important ones. They ensure that when the server restarts after a reboot (for example) the virtualenv is activated. If you forget this (as I recently did) the app will fail to start; the error log (in ~/logs/user/error_appName.log ) will report that some module could not be found.
showing 5 of 15
show all
|
|
They are a little old, but these instructions on our forums should still work perfectly. After following our documentation you should already have most of it done :) Ugh. I'm not nearly smart or dedicated enough to follow those instructions. I develop on a Linux box, each python project has its own virtualenv. It sure would be nice if I could just ship that entire mess up to webfaction, and know it is running in production the same way it runs in test. This would also make the management of libraries much easier. I could finally type "yolk --list" and get the same set of libraries the wsgi app sees. |
|
I'm trying to learn along with you guys and when I add the paths to my .bashrc and sourced it I get this error. Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named virtualenvwrapper.hook_loader virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7 and that PATH is set properly. We would have to see the exact lines you are entering. You may submit a support ticket if you would like us to look in real-time. Thanks John, I didnt want to use up support time of webfaction since I'm learning and not so much doing it for a client but if you think that's best I will give it a go. Thanks for this post, it's been very helpful. Here's some of what worked for me (after following these instructions):
It seemed to make more sense to use pip to install virtualenv/wrapper... Maybe there's a good reason to use easy_install? Also, not sure if this will help others who get the "No module named virtualenvwrapper.hook_loader ..." error, but this fixed it for me (relevant contents of my .bashrc):
|