I have set up already my configuration so that it will run the server remotely. When I click run, I see the command used:
ssh://vagrant@localhost:2222/usr/bin/python -u "C:/Users/MyName/ProjectName/config/manage.py" runserver localhost:8080
(I've replaced the directory names for anonymity reasons).
When I do run this, It fails (obviously) because it's using a windows path to my manage.py Specifically the error I get is
`/usr/bin/python: can't open file 'C:/Users/MyName/judgeapps/config/manage.py': [Errno 2] No such file or directory
What I can't figure out after extensive googling, is how to force django to use a path on my vagrant machine. How can I go about doing this?
Professional feature: download PyCharm Professional to try. Django project is intended for productive web development with Django. PyCharm takes care of creating specific directory structure and files required for a Django application, and providing the correct settings.
In the Settings/Preferences dialog ( Ctrl+Alt+S ) under the Languages and Frameworks node, click Django. In this page, choose the desired Django project. In the Manage.py tasks section, specify the following: In the field Manage script, specify the desired manage.py script.
PyCharm supports the latest Django versions. The corresponding Python versions depend on Django.
Press Ctrl+Alt+S to open the IDE settings and select Plugins. Install the Vagrant plugin.
The trick is creating a Python interpreter in PyCharm, and configuring the project to use this interpreter.
Note: The following applies to PyCharm Professional 4.0.
Tools->Vagrant->Up
Tools->Start SSH Session
. Select Vagrant at [VagrantFolder]
from the list that appears.which python
. This will give you an absolute path to python on your virtual machine.File->Settings->Project->Project Interpreter
. Click the + button to create a new one.Vagrant
. Your Vagrant instance folder
should be the location of your VagrantFile on your host machine. Python interpreter path
should be set to the absolute path you found in step 3 above.up
in order for this to work.Run
menu, select Edit Configurations
Django Server
Host
to 0.0.0.0
. This will bind the runserver
command to an external IP.Run browser
and set the URL to the host/port you mapped to your VM in your VagrantFile (for example, if I map my host's port 8080
to Vagrant's 8000
, I'd use http://127.0.0.1:8080/
)Python interpreter
that you set up in the above section from the Python interpreter
dropdownpath mappings
(this is sometimes optional, depending on where your VagrantFile is stored).Run your project, and enjoy the glory that is Vagrant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With