What directory is GCP Cloud Shell working in? - python

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.

Related

Python on server, local development using Pycharm- Setup possible?

Few members in the development team are starting to work on Python. They plan to use PyCharm IDE. They will be using a Citrix MyDesk. The problem with MyDesk is that the folder path keeps changing at every login, so I assume python.exe interpreter location cannot be configured.
We have a server. Is it possible to setup Python and the packages on this remote server? Developers will use PyCharm in their MyDesk and point to python.exe in the remote server.
Is this setup possible?

Django project - How to make separate virtual environments for different devices but for the same project (i.e PC and Laptop)

I have a Django project that I'm using for university, and it uses a virtual environment following the tutorial that VSCode provides on Python and Django on their website. As I use multiple devices (PC/Laptop), I share the code with myself via Google Drive. On my PC everything works fine, but when I try to run the local server on my laptop, I get an issue where there is "No python found", which is supposedly due to the pyvenv.cfg having the Python path set to the path where my Python is on my PC, which is obviously not the same as my laptop. I've been unable to find the answer so far, so how can I have 2 separate virtual environments using VSCode where I can easily switch between working on my PC and Laptop?

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

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.

Using local Python environment in IntelliJ

I've checked out a python project with a local environment. I am trying to add the local env in IntelliJ on the Project Structure > Platform Settings > SDKs screen, I select 'Add local' and navigate to [my_project]/env/bin/python.
I then see the message "Invalid Python SDK - Cannot set up a python SDK at Unknown at '[my_project]/env/bin/python'. The SDK seems invalid."
If I then click ok, I see the message "Cannot Detect SDK Version - Probably SDK installed in '[my_project]/env/bin/python' is corrupt"
In the logs I see the messages
"ERROR - ns.python.sdk.PythonSdkUpdater - Failed to determine Python's sys.path value"
and
"...env/bin/python: cannot execute binary file".
Any advice would be much appreciated.
I found the answer, and including it here for completion even though it's a kind of specific case.
I have a project shared between a docker instance and my local machine. The 'env' I was trying to use on the local machine had been created in docker, and therefore referred to an instance of python that existed on docker.
I had to create a second environment on my machine, and now all is working well.

Vagrant and Google App Engine are not syncing files

I am currently using Vagrant to spin up a VM to run GAE's dev_appserver in the Virtual Machine.
The sync folder works and I can see all the files.
But, after I run the dev appserver, changes to python files by the host machine are not dynamically updated.
To see updates to my python files, I have to relaunch dev appserver in my Virtual Machine.
Also, I have grunt tasks that watch html/css files. These also do not sync properly when updated by editors outside the Virtual Machine.
I suspect that it's something to do with the way Vagrant syncs files changed on the host machine.
Has anyone found a solution to this problem?
Finally found the answer!
In the latest version of google app engine, there is a new parameter you can pass to dev_appserver.py.
using dev_appserver.py --use_mtime_file_watcher=True works!
Although the change takes 1-2 seconds to detect, but it still works!

Categories

Resources