Copying Django project to root server is not working - python

I hope you can help me.
I have been building this webshop for the company I work for with Django and Lightning Fast Shop.
It's basically finished now and I have been running it of a virtual ubuntu machine on my PC. Since it got annoying leaving my PC on the entire time, so others could access the site, I wanted to deploy it on a root server. So I got a JiffyBox and installed ubuntu on it.
I managed to get Gnome working on it and to connect to it with VNC. I then uploaded my finished project via FTP to the server.
Now I thought I would only need to download Django-LFS, create a new project and replace the project files with my finished ones.
This worked when I tested it on my virtual machine.
To my disappointment it did not work on the root server. When I tried running "bin/django runserver" I got an error message saying "bash: bin/django: Permission denied" and when I try it with 'sudo' I get "sudo: bin/django: command not found"
I then realized that I had downloaded a newer version of Django-LFS and tried it with the same version to no avail.
I am starting to get really frustrated and would appreciate it very much if somebody could help me with my problem.
Greetings, Krytos.

I have no idea what a "root" server is. But you don't deploy Django by just copying the files: you need to configure the webserver. The documentation has a very comprehensive explanation.

I know some of this tip can be obvious but never knows:
Do you update all your settings in settings.py ? (paths to static files, path to project...)
Wich server are you using ? django server ? apache ? nginx ?
Do you have permissions over all file in the project ? You should check that the owner of the files is the user you have, not root. If the owner is root you'll have this permissions problem in every file that is owned by root.
Are you using uwsgi ?
Have you installed all the apps you got in your VM ?
Have you installed the SAME version you got in your VM ?
When I move a project from VM to real server I go over this steps:
Review settings.py and update paths
Check permissions in the folder that the web server may use
I have a list with the packages and versions in a txt file, let's call it packages.txt
I install all that packages using pip install -r packages.txt
I allways use apache/nginx, so I have to update the virtualhost to the new paths
If I'm using uwsgi, update uwsgi settings
To downgrade some pip packages you may need to delete the egg files, because if you uninstall a package and reinstall it, although your using pip install package==VERSION, if you have a package already downloaded, pip will install this one, even if the VERSION is different.
To check actual version of pip packages use pip freeze
To export all pip packages to a file, to import them in other place: pip freeze > packages.txt nad to install packages from this file pip install -r packages.txt

Related

python: How to install virtualenv without internet connection

I am filling in for someone while they are on vacation and I am new to python. I've been asked to install several packages in a virtual environment. The big catch is the server cannot be on a public net so I will be downloading the software on a different server and copying it to the server where the researcher will be working.
I found another thread "Install Virtualenv without internet connectivity" at Install Virtualenv without internet connectivity, but that doesn't fit the situation I am in - it looks like they can start from a server on the net to complete their installs and want to share that virtualenv to other systems in a lab environment that may not have Internet connectivity.
Another thread "python: How to create virtualenv without internet connection" at python: How to create virtualenv without internet connection, is similar but it looks like they already have virtualenv installed. I don't find virtualenv installed here.
This Windows Server 2016 system is locked down where I cannot copy and paste the commands I ran to provide the information below, so forgive any typos in the hastily written message. I found the python version installed by:
python --version
Python 3.6.2rc1
I have not been able to find an installer to download for virtualenv. Do I need to download the Python installer again, re-run it and select additional options?
Thank you for any help you are able to provide.
edited to add:
Based on feedback, I changed the command (in an administrative command window) to
python -m venv [path] and I have been able to make some progress.
I have the ability to download gz, whl or other files and move them to this server to run them there, but this server cannot be put online to download the installers directly nor can it connect to a repo to download dependencies. I cannot set up the environment on a different machine that has connectivity and share it without violating the security requirements. Thank you for the link to the Python Package Offline Installation thread - I think I was so narrowly focused on the virtual environment that I missed that post.
You're using Python 3.6, which means venv is included and pip can be bootstrapped if necessary. Creating a venv does not need internet access:
python3 -m venv .venv --prompt=myvenv
Installing pip does not require internet access:
python3 -m ensurepip
Installing a package from a local file does not require internet access:
python3 -m pip install --no-index --disable-pip-version-check ./mydist.tar.gz
Should you have more than one package to install (for example, if mydist has dependencies) you may specify a local directory as your --index-url instead of the index defaulting to PyPI.
A solution for people on older versions of Python is covered here.

Django and file permissions problems

I installed Django 1.5.4 on my MAC OSX 10.6.8. I created a test project.
And I am unable to edit any of those files, it says read only. I can sudo it and do the modifications.
But what are the other files it may try to access during run time, if they are read only then my application is not working, for example: sqlite database file "storage.db". Can I change the file permissions on the project root folder level and have it applied all the files inside?
Even If could do that, why Django starting project like this? I tried Virtualenv as well, but of no use same thing happens
I figured out the problem. Its the way I installed django in my system. Previously I used sudo easy_install , but this time I created a virtual env and installed django with pip and it worked well. Virtual environment is the best solution for package installation in python. It wont mess with system packages.

Importing and debugging a Python Django project made in a different environment

I am working on a Django project that was created by another developer on a different machine. I see that in the root of the application, there is a .virtualenv directory. Is it possible to simply setup this project locally on my Windows machine using the project settings and Python version (the app uses 2.7), so that I can run it like a local Django application so debugging is feasible?
I have access to the development web server and have copied the full source of the app down to my Win7 machine but cannot seem to get things setup correctly to run the app locally so I can debug.
I currently have Python 2.7, 2.7.5 and 3.3.2 installed on my local dev machine. I would call myself pretty new to Django and Virtualenv.
If anyone has any guidance on how I can get my environment straitened out so I can run the app with debugging, I would be very thankful.
Thank you in advance.
Using a virtualenv environment created on a different machine is not recommended. There are things hard-wired for the particular system it was created on, and some apps may have components compiled for that particular system.
You should create a new virtualenv environment on your machine, install dependencies and move the Django project there.
Note on installing dependencies - there might be a file named requirements.txt somewhere. If it's there and it's kept up to date you can install all the dependencies by running a single command while in your virtualenv:
pip -r requirements.txt install
If you can't find it ask the other developer to create it. He just need to do this inside his own environment:
pip freeze > requirements.txt
I once faced the same problem and it took me so much time to configure another environment that I eventually had to create a VM with the same version of OS and libraries. I then made a raw copy of the project and it worked fine.

How to relocate python installation installed as non-root user on another server to another server in different directory?

We have two linux servers, one is on private network which does not have internet access. The other is on public network which has internet access. Both the servers run the same RHEL-5 OS.
On as server which has internet access, I have installed python under my home directory as non-root user. Then I used pip to install other packages, pip also resolves dependencies and install the required dependencies.
How I can relocate this python to a server which does not have root access ? Also I want to relocate it as root under different directory ?
Why I want to do this ? Since the private server does not have internet access pip won't work for installing 100s of modules and there dependencies. Since the servers are running the same OS release, is there any easy way to relocate python installed on one server to another server though in a different directory ?
If possible, I'd try to go through the front door and actually install the packages on the other server. Cloning of all packages should in principle be equivalent to the following:
On the first machine (with Internet access and installed packages):
mkdir /tmp/pypackages
pip install -r <(pip freeze) -d /tmp/pypackages
On the second machine:
Copy the packages to /tmp/pypackages
Install them:
cd /tmp/pypackages
pip install *
(either as root or as a regular user).
Note that when I try to run the first set of commands on my machine, I get some errors which I blame on the fact that not all of the packages shown by pip freeze were actually installed with pip. You may need to filter that list as well. It'll probably be easier to save the output of pip freeze to a file and edit it.
P.S. python itself can also be downloaded, transferred, and installed locally by means of the system package manager.

How to get Django classifieds running on my local server

I am starting on a project for classified ad listing site and found a template to get me started.
The installation instruction on git are not clear to me.
I created virtual env and installed dependencies using pip but I can't finish the installation process: manage.py runserver could not be executed and showed "could not find module sorl.thumbnail".
I think there is some error due to folder structure but cannot figure out what. Any ideas?
This is my folder structure.
It seems that the dependency sorl.thumbnail is not (successfully) installed.
Try running pip install sorl-thumbnail==11.05.2. That should install the module (in the version required by django-classifieds according to the requirements.txt). Check the output for any errors.
Also, make sure that you are using the right environment.
My only guess is that you either forgot to install sorl.thumbnail or that it is in a separate environment than django-classifieds. To add it manually, download the zip from the specified URL, extract the zip, and, in a command prompt/terminal in the directory you extracted the zip into, and run python setup.py build and python setup.py install.

Categories