I'm new to Django and still learning.
Currently I have server set up with the follow folders:
'www'
'db'
'private'
Where and How do I install django framework on a server?
It can be accessed with ftp and ssh.
Currently. I just know that php works and loads within the www folder.
Do I have to install python?
Thanks everybody in advance.
It is a good practice to use a virtual environment such as virtualenv. After you install virtualenv and activate it, you can then install django via pip install django which will install Django to your virtualenv. An easy way to organize the package requirements is to put the package you will use in a requirements.txt file, which looks like something like this:
Django==1.4.1
Mako==0.7.0
MarkupSafe==0.15
You can then install all the required packages with pip install -r /path/to/requirements.txt
Setting up Django for deployment:
Cleanest & Fastest server setup for Django
official django doc 1 and 2
Basic Django deployment with virtualenv, fabric, pip and rsync
Related
I am trying, for the first time ever, to deploy a ML model, using Flask. I'm following the instructions from the link below.
https://towardsdatascience.com/deploy-a-machine-learning-model-using-flask-da580f84e60c
I created three separate and distinct .py files named 'model.py', 'server.py', and 'request.py'. I open my Anaconda Prompt end entered this: 'C:\Users\ryans>C:\Users\ryans\model.py'
Now, I get this.
I definitely have Numpy installed! Something must be wrong with my setup, or maybe the way I am starting the process is wrong, but I'm not sure what the issue is. Has anyone encountered this problem before.
I would suggest the following steps since you mentioned its your first time and when deploying a project for experimenting, it's good practice to put it in a virtual environment, which we can do with the virtualenv tool.
Assuming you already have pip installed, install virtualenv:
C:\> pip install virtualenv
Create a fresh working directory, switch to it and clone the repository from Github mentioned by the author of the article:
C:\your-working-directory\> git clone https://github.com/vyashemang/flask-salary-predictor.git
Start virtualenv in the repository's top directory
C:\your-working-directory\flask-salary-predictor\> virtualenv env
Activate the created batch file, \env\Scripts\activate.bat:
C:\Users\'Username'\venv\Scripts\activate.bat
Now in the virtual environment, install all requirements:
(env) C:\your-working-directory\flask-salary-predictor\> pip install -r requirements.txt
You can now run the model.py like you have above. I'd suggest that you run the server.py using gunicorn or on Windows use waitress according to this post so that instead of running request.py every time you want to send a request, you can use Insomnia or Postman to send API requests.
I am attempting to deploy a Django app to a Linux server via an Azure App Service. During the deployment via Azure Devops Pipelines, all requirements are installed from my requirements.txt file in the root directory of my project.
I have used the Kudu console to confirm the dependencies are installed to /antenv/lib/python3.7/site-packages on the server, however, the app crashes due to an error:
ModuleNotFoundError: No module named 'django'
I am beginning to think the virtual environment may be failing to actually start but do not know how to check or how to start it if this is the case.
Has anyone had a similar issue to this during their deployment? If so how did you resolve it? Any advise is much appreciated. Thank you!
Newest
Change target path ,--target="./.python_packages/lib/site-packages" .
- bash: |
python3.8 -m venv worker_venv
source worker_venv/bin/activate
pip3.8 install setuptools
pip3.8 install --target="./.python_packages/lib/site-packages" -r requirements.txt
displayName: 'Install Application Dependencies'
You need to install a new Python runtime at the path D:\home via Kudu site extensions.(Windows)
The problems is, azure app service use virtualenv by default, so the requirements.txt package is automaticly installed to python in the virtualenv... so I just edit the deploy.cmd to install requirements to python (extension)
For more details, you can refer Peter Pan's answer in below post.
Why is the azure app service django deploy keep failing?
I'm an experienced developer, but not very familiar with Python and Pyramid.
I'm trying to follow some (a bit old and unclear) instructions on deploying a Pyramid web application. My OS is Ubuntu 16.04.
The instructions say to install virtualenv and Pyramid - I do so with apt install virtualenv and apt install python-pyramid. Then they say I should run the app in a virtual environment, so I build that with virtualenv . -ppython3, and activate it with source bin/activate. I install the application from a ready-to-run buildout from GitHub. The buildout includes a "production.ini" file with parameters to pserve.
But Pyramid is not included in the virtual environment built with virtualenv. (There is no "pserve" in the bin directory, e.g.) So I can't run the applications with bin/pserve etc/production.ini, as the instructions say. And if I try with only "pserve", I get errors when trying to access files like "var/waitress-%(process_num)s.sock". Files that the app excepts to find in the virtual environment.
I've looked for flags to tell virtualenv to include Pyramid, but couldn't find any. Am I overlooking something? I'd be most grateful for some help! :-)
/Anders from Sweden
Perhaps you might want to try installing Pyramid in your virtual environment using pip, since apt-installed libraries are installed into /opt, rather than being visible to Python. In the guide, it seems like you're wanting to install Pyramid through the virtual environment so that it can be used by your program, so I think you'd be best using pip rather than apt-get. I did a quick Google search, and it seems like this is the library you need. Here, all you'd have to do is run the installation command once you've already entered the virtual environment with pip install pyramid. This way, you should only have access to it within the virtual environment, as well!
You mentioned it's using buildout - I assume this is zc.buildout. buildout usually manages its own virtualenv and handles installing all of the necessary dependencies. It really depends on how that buildout is configured as there's no standard there for what to do or how to run your app. I would normally expect pserve to be exposed in the bin folder, but maybe another app-specific script is exposed instead.
I'm trying to deploy my Django site on Heroku, and thus, I need a requirements.txt file with the necessary packages that Heroku needs to install for me. I understand Django is a necessary package to be installed. Unfortunately, Django isn't included in the file when I run pip freeze > requirements.txt. Why is this? I'm not sure what to show you so you can tell me what's going wrong. Let me know and I'll add it. FYI the site hosts just fine on my local computer, so Django is definitely installed.
Sounds like you are working in a virtual environment, yet your Django dependency is installed globally. Check which Python packages are installed globally and uninstall Django (you probably don't need it globally). Then install it into your virtual environment. Now the freeze command should output Django as well.
General note: Most packages should be installed into your project virtual environment. There are only few packages where it makes sense to install them globally (eg aws management tools).
We have a python(3) venv rest api. In the same venv we have also installed and configured the application server uwsgi the api is running on. And we are looking for a clean way to deploy it.
Until now we are deploying with is a simple script that creates the venv install the dependencies from pip and then runs the app.
I am wondering if using snap would be possible to package everything nicely and simply install them on a server.
Is that possible or a good practice to deploy a web api this way?
Thanks for your time.
Yes, you can do this with snaps. You can use the python plugin module with snapcraft which extends your python path with a virtualenv.
Also, Its pretty easy to do this with a deb.
dh-virtualenv lets you use standard debian packaging tools. https://labs.spotify.com/2013/10/10/packaging-in-your-packaging-dh-virtualenv/
It is your choice.