Will my virtual environment folder still work if i shift it from my local machine to a shared folder? - python

Currently, I have a Flask app waiting to be shifted to a shared drive in the company's local network. My current plan is to create a virtual environment inside a folder locally, install all the necessary dependencies like Python3, Flask, Pandas and etc. This is to ensure that my Flask app can still reference to necessary dependencies to run the app.
As I can't access my shared drive via command prompt, my plan is to create a virtual environment locally then shift it to the shared folder together with all the scripts required by my Flask app. Will the app be able to run on the shared drive in this manner?

The standard virtualenv hardcodes the path of the environment into some of its files in the environment it creates, and stops working if you rename it etc. So no, you'll probably have to recreate the env on the destination server.
Perhaps your app's startup script could take care of creating the env if it's missing.

Related

installing python in a docker container

I'm new to coding and been fiddling around with docker containers and services
I have installed a temporary vscode server on my raspberry and deployed on my local lan for accessing it from various machines
Now i've been trying to create a flask app and run it from the container and trying to figure out how to publish and run the flask web server since i can't figure out what ip should i host it on (the default i always used was host=127.0.0.1 port=8080, but that would bring me to the local machine i'm visiting it from)
So while i was troubleshooting to understand what to do with exposed ports etc i've stopped the container and changed the docker-compose file, (i have a path set for the config's permanent storage, so my vscode setting are actually saved and persistent between deployments)
But I'm having the problem that every time i stop and re deploy the container i loose my python3 installation, and have to re run apt-update, apt-upgrade, apt install python3-pip and every python packages i need for the project
Where am i going wrong?
Silly question, but where does python get installed, and why isn't it persistent since i have my config path set?
I read that python gets installed in usr/local/lib, should i also map those directories to the persistent storage folder?
how should i do that?
thanks

Do I need to commit .env files into the repository?

I have just started learning backend dev using django. My question is do I just commit the project files in the server folder alone, or should I also commit the .env folder to the repository?
I have done the following:
I have created virtual environment and I have also installed django in venv.
I have setup a django server and super admin.
I have setup the config.json to protect my API key.
Included the same in .gitignore.
What happens if I do or do not commit .env?
Assuming that your .env folder is your virtual environment, no you should not commit it.
The virtual environment should be rebuilt on the server using your requirements.txt file. The local environment you built on your development machine may have operating system specific binaries, and other compiled code that was generated for your local environment.
The server will have different compiled binaries, and therefore should rebuild the virtual environment using: pip install -r requirements.txt.
You shouldn't commit/include your .env file in your git repo because env stands for environment. You will different environment variables for your LOCAL, STAGING(development), PRODUCTION environments.
i.e. your LOCAL .env file might have something like
WEB_HOST=localhost
WEB_PORT=8000
ALLOWED_HOSTS=127.0.0.1, localhost
but your PRODUCTION .env will have something different like
WEB_HOST=www.mysite.com
WEB_PORT=8080
ALLOWED_HOSTS=www.mysite.com
Which is why you can't include your .env in your repo and should be created depending on the environment.

What directory is GCP Cloud Shell working in?

I'm trying to set up a basic Python development environment through GCP's Cloud Shell command line interface and I'm trying to activate a virtualenv to run some stuff in Dataflow. However I'm finding that I'm confused as to which directory the Cloud Shell is operating in.
My prompt shows the following:
my_name#cloudshell:~ (my-project-name)$
I installed virtualenv on my local machine in a prior session, and just now tried to activate a virtual environment through this previously installed activation file on my local machine with
source C:/Folder1/Folder2/virtualenv/Scripts/activate
but I kept getting "No such file or directory" even though this is the correct path. After some sleuthing, I found out that Cloud Shell is operating from the following directory by default:
/home/my_name/C:/Folder1/Folder2/virtualenv
(in which there's no 'Scripts' folder, which was causing the directory error)
This /home/my_name/... prefix directory is nowhere to be found on my local machine. I'm realizing I have no idea what directory the Cloud Shell is working from.
I have a feeling that I've installed a lot of my environment files under this weird ghost directory (possibly inadvertently) and so now I've lost control over the structure of my development environment, because now I have virtualenv files on my local machine, and some other virtualenv files in this ghost directory.
Can somebody explain
1) Where this directory is located on my machine, if it's even there at all?
2) If I'm supposed to setup my entire environment from within this ghost directory?
3) If I just messed up my environment installation from the start and should start over?
Appreciate any help, thanks.
Google Cloud Shell (not to be confused with gcloud program) runs in a Virtual Machine in the Google Cloud. It knows nothing about your desktop. You are able to upload / download files from / to your desktop using the web browser that contains the UI for Cloud Shell.
Unless you're using sshfs on Mac or Linux with gcloud alpha cloud-shell to mount your local directories (as detailed in this blog post), Cloud Shell won't have access to your local filesystem.

How do you run InstaBot.py on OpenShift?

To run InstaBot locally, you just clone the repo, install the requirements.txt, put in your login credentials in example.py, and run python example.py. I do not know how this translates to OpenShift.
Let's say you push your code to your own GitHub repo with the login credentials in environment variables (in an git ignored file). You can set environment variables on the OpenShift dashboard, but where's the part where you specify python example.py?
For OpenShift, if example.py is a self contained Python web application, then you would need to rename it as app.py, or add a .s2i/environment file to your repo and in it add:
APP_FILE=example.py
The script should then ensure it is listening on all interfaces, ie., 0.0.0.0 and not just localhost. It also needs to use port 8080.
With that done, you can then use Python S2I builder process in OpenShift to deploy it. The packages listed in requirements.txt will be automatically installed for you.
if not familiar with OpenShift, you might consider reading:
https://www.openshift.com/deploying-to-openshift/
It is a free download.
For details on the Python S2I builder and what environment variables you can set to customise it, see:
https://github.com/sclorg/s2i-python-container/tree/master/3.6

how to deploy apps developed in virtual env

I have a flask based app, and it's now running with virtualenv on my dev machine. Now I want to deploy it to my virtual host. Sadly, this virtual host is running flask 0.6, and I want flask 0.10. I don't have enough privilege to upgrade it.
Can I just upload my whole virtual environment, and to use my own version of flask, and how?
My idea is change the PYTHONPATH, how to get rid of the old version and add the new into it?
Any help will be appreciated.
Uploading your virtualenv probably won't work. There is a good chance that something in the virtualenv is dependent on the exact file paths and versions that won't match from your machine to the virtual host.
You can upload the virtualenv tool, make a new virtualenv, and then install the version of flask you want inside that virtualenv.

Categories

Resources