Flask run not recognizing python-dotenv on windows - python

So I'm running python 3.7 on Windows and I have installed python-dotenv in my virtual environment as well as flask. I have a .flaskenv file in the root of my project where I execute flask run, it looks as if python/flask is not recognizing python-dotenv .flaskenv file it ignores my parameters and states that I do not have a FLASK_APP value assigned. This same setup works fine on a Linux workstation. Is there something different to configure on windows to get this to work?
Thanks ahead of time.

I ran into the same issue and resolved it by executing python -m flask run instead of flask run. The -m allows modules to be located and executed.

.flaskenv seems to be working fine on Windows 10. Have you tried creating a new file named .flaskenv, without specifying any extension, in Visual Studio Code? A .flaskenv file of FLASKENV FILE type gets automatically created. I have in there a single line FLASK_APP=yourFileName.py.
Hope this helps.

Related

How do I activate a VSCode environment from ssh?

I am currently using VS Code on a server (through SSH). Everything works fine, and I installed Python packages and work with Python notebooks.
Now, I want to login to the server (not a problem) and run the Python code I created on VSCode, rather than executing it remotely.
My main issue is that I am not sure how to activate the Python environment (if there is one) that VSCode server's run so that the code can execute.
Is that possible?
I see I have a .vscode directory in my home directory, and there are package installation there.
After connecting vscode remotely, you can use it as a regular vscode, which is no different from running Python files locally:
install python
install pylance extension
choose correct interpreter
edit your code and run the python file.

Deploying flask including created venv by manipulating pyvenv.cfg

I'm new to python and venv and I think I'm misunderstanding the design of venv here.
I've created a flask project with python 3.8 locally(win 10) and planned to deploy to a server(windows server 2016) that DOES NOT have python 3.8 installed.
I've created virtual environment locally with below cmd:
python -m venv env
After checking the pyvenv.cfg file, the home key shows:
home = local\absolute\path\to\python\used\to\create\venv
As expected, I copied the whole project folder to the server and activate the venv returns me with
no python at local\absolute\path\to\python\used\to\create\venv
So I changed the pyvenv.cfg home key to the python interpreter in the deploy venv
home = deploy\absolute\path\to\Scripts\dir\in\venv
Yet if I run activate.bat and start my flask project, the process just hanged there and flask isn't responding.
Besides, If I simply run activate.bat and type in python, it just hangs there and not even the python version is showing up. My problems are:
Is manually changing the home key in pyvenv.cfg to the interpreter included in the venv a good practice to get the project running when target python version is not installed?
If yes, what are the possible reasons causing my process to halt? I assume that everything needed to run python are included in the venv.
If not, why doing so causes the process to halt?
Or should I get python 3.8 installed instead? Since i found some saying the only way to get it running is through pyinstaller if python is not installed, but wrapping whole flask app to an exe doesn't seem practical
Any help is appreciated, thanks in advance!

How to change python-path of supervisor?

I'm working in a flask REST API using python3, supervisor and gunicorn. I have installed all the pip modules. when i run the supervisor's config file it shows following error. Any help would be appreciated.
Using virtual environment and install python 3.x to it. After that it works fine.

Pycharm can't find Thrift ttypes file

Short, problem description:
When I try to run/debug a pylons project using paster via PyCharm it can't find the Thrift ttypes module that is being imported. If I run paster manually it works fine. The error message is just:
File "/myproj/lib/timetools/__init__.py", line 13, in <module>
import lib.thrift.common.international.ttypes as international_ttypes
port Error: No module named internation.ttypes
Long description:
I am trying out PyCharm for the first time. I have downloaded and installed it on Mac OSX Yosemite and pointed it at the project directory and I have configured the virtual environment (python interpreter).
Project structure (the part relevant to this question) looks like:
/myproj/lib/timetools/__init__.py
/myproj/lib/thrift/common/international.thrift
/myproj/build/py/lib/python2.6/site-packages/lib/thrift/common/international/ttypes.pyc
/myproj/mypylons/config/development.ini
My virtual environment is set to /myproj/build/py/bin/python.
If I go to my project root directory and run my activate script to use my virtual environment, I can successfully run:
paster serve config:/myproj/mypylons/config/development.ini
And the server starts up and responds on the appropriate port.
The way I configured PyCharm to run the pylons it tries to execute the following:
/myproj/build/py/bin/python "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py" --multiproc --client 127.0.0.1 --port 53432 --file /myproj/build/py/bin/paster serve config:/myproj/mypylons/config/development.ini
And I get the error above. It would seem that PyCharm can't find the international/ttypes.pyc file in my build directory even though it is included in the project. I tried setting the working directory to /myproj/build/py/lib/python2.6/site-packages but that didn't help.
As a note, when I look at the Project Interpreter configuration I do see the Thrift package there with a path of /myproj/build/py/lib/python2.6/site-packages.
Help!
From my experience it seems like you have to tell PyCharm exactly where the files are through the Project settings:
Go to Settings and then to Project Structure
Find the folder to which the ttypes are compiled to and click on it
On the Mark as: line, above the directory tree window, click on Sources (should be colored blue)
Click on 'OK' and you should be good to go
Hope it helps!

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.

Categories