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!
Related
Started to learn python a few weeks ago, i made and ran some basic files. all worked well.
At one point i uninstalled python and reinstalled it.
i continued making and running new files no problem.
now i am trying to go back to and run some of my old files and i am getting an error.
Error:Cannot run program "/Users/paulthomas/PycharmProjects/plotting/venv/bin/python" (in directory "/Users/paulthomas/PycharmProjects/plotting"): error=2, No such file or directory
In pycharm i open the folders and hover over the python file section and it says i have a symlink error. How can i fix it?
i have been using pipenv in my newer projects as they are django projects. But this project im trying to get to run is just a basic python project.
If you have reinstalled python, it is likely that the virtual env is linking to the wrong original python binaries.
You can either relink the files (by finding what they should have linked to, and relinking them) or if you have a requirements.txt file for the environment, delete and recreate the virtual env.
You can either do this through pycharm's environments system, or by using:
python3 -m venv <your environment name>
From your screenshot, your environment name is venv.
If the reinstalled python is a different version, it's likely safer to recreate the virtual env than to try linking things that may end up being inconsistent.
The answer to this question could be "You're as dumb as a wooden bowl" but I have searched a lot and haven't found a solution without installing python on other computers.
I have a python/flask web app that I need to distribute to many users. However, I can't install python on all those computers and there is no computer which everyone can access. And I cant serve the app internally from a server either. Yes, that's what I'm dealing with.
I have saved the git repo it in a network drive that everyone can access. I hoped I could run a batch file to spin the localhost server from a copied environment for the user and then use the web app.
I copied a conda environment over to the network drive and tried to use that but that gave me a Importing the numpy c-extensions failed error.
I tried including a pip environment (.\env) in the folder. So I thought any user could just activate the environment using the batch file ...
cd %cd%
.\env\Scripts\activate.bat
.\env\Scripts\python.exe run.py
but it's not working.
The .\env\Scripts\activate just crashes. I amended the activate.bat set "VIRTUAL_ENV=%cd%\env" to ensure it uses the current folder. Still crashes.
If I exclude that then .\env\Scripts\python.exe run.py still looks for a python installation at the path I have on my machine rather than the path I provided above.
Is there a solution to this?
All the computers will be using Windows but may vary between Windows 7 and Windows 10. I'm doing the development from my Windows 10 computer.
After activating venv My below code worked:
(Monday) C:\Users\Resurctova\Desktop\PoraPuski\Monday>python new.py
Output :
testing
since the new.py has code to print testing
As Monday is my venv I activated it and executed the script.
Do not execute in Scripts folder of your venv environment
Have you though about creating an exec file and that will save all your folders. Using a tool lik PyInstaller. You just need to share the output exe file without installing python.
I've just setup a new environment for my project and uploaded a python repository including bin, lib and project folder. I'm pretty sure I did same previously and it worked without problem. Now when doing the same on an AWS environment I get the error
-bash: /projects/scrapy/bin/python2.7: cannot execute binary file. However when doing source /projects/scrapy/bin/activate it successfully activates the environment.
From what I understand, python should be able to execute without any issue no matter the environment ?
Any help or pointing to the right direction would be much appreciated!
python should be able to execute without any issue no matter the environment ?
No, the Python binary is tied to your specific OS and computer architecture. Python source code can usually be run on different machines (provided you didn't use OS-specific features), but that's only made possible by compiling a Python interpreter for the specific target environment first.
In other words, a Python binary compiled to run on macOS will not work on Linux.
All that source bin/activate achieves is that it configures your terminal setting to use the bin directory as the first directory on the PATH search path. This doesn't make bin/python work in another environment, it just means that both environments have a working shell interpreter that can run that script.
Create a new virtualenv with a Python binary compiled for Linux, and install the same packages there. Use Pipenv or a requirements.txt file to transfer the dependencies from Mac to Linux.
For example, using Pipenv you'd copy over the Pipfile and Pipfile.lock files to the other computer, then run pipenv install in the directory there and re-create the virtualenv and dependencies from those files.
I recommend you read up on Python development best practices in the The Hitchhiker’s Guide to Python; this includes such topics on how to manage an environment for a project.
I am facing a rather peculiar problem. I have built a Django application and only while deploying it, I created a virtual environment(I didn't use virtual environment while building and testing it locally). Now when virtual environment is activated and also when deactivated, the HTML templates cannot be found. Below is the screenshot.
Seeing this statement,
Python Executable: /home/shadowsaint/Programs/Django/zoomtail/venv/bin/python
I went back to terminal and typed which python command. For that it shows
/home/shadowsaint/Programs/Django/zoomtail/venv/bin/python
Now when I deactivate virtual environment also the which python command gives the same thing.
But when I delete the venv file, and run which python it gives,
/usr/bin/python
And now the application runs fine, i.e., the HTML templates are being found.
I have three questions here.
When I activate venv, the python used from venv/bin is fine. But even when I deactivate virtual environment why the same python is being used?
What does python package(both the versions are same) have to do with templates being found?
Is the underlying principle here the same as that in here too - No module named PIL in heroku though it is installed
You have a misconfiguration at your Heroku environment, first check if your requirements was installed, use shell (python manage.py shell) and try import some of them to see if they throw errors... if passes ok then try to access any url from your project... if template breaks maybe the problem is in your Template_DIR at your settings
Obs.: check if your django commands like shell, migrate... works when running heroku run bash with your venv activated
Try follow some of this steps:
https://devcenter.heroku.com/articles/getting-started-with-python#introduction
http://docs.python-guide.org/en/latest/dev/virtualenvs/
Verify in project settings.py that INSTALLED_APPS list actually contains your app name.
INSTALLED_APPS = [
'your app',
'django.contrib...'
.....
I'm trying to build a simple API server using Flask that will validate and store international phone numbers using this phonenumbers.py. I previously installed Flask and several Flask extensions in a virtualenv, and started building my app. So far so good. But after downloading and installing phone numbers.py using its own installer, I found that python running inside virtualenv could no longer find my app script! Looking at the directory, it's sitting right there, but python does not recognize it any more. The only other wrinkle I can think of is that after doing the install, I used an external text editor (outside the venv) to edit my app script and re-save it.
What have I done wrong?
I compared my environment variables inside and outside virtualenv. They are the same except for the following 3 additions:
VIRTUAL_ENV=/Users/tokrum/callcenter/venv
PATH=/Users/tokrum/callcenter/venv/bin # (was added to the beginning of my $PATH, but the rest of pre-existing PATH is as before….)
PS1=(venv)\h:\W \u\$
My app is called callcenter-v0-1.py. It lives in a directory called /callcenter/, along with the phone numbers-7.0.1 and venv folders at the same level of my directory structure.
Thanks for any light you can shed on this.
Install Flask_script in your virtual env using
$pip install Flask-Script
Make sure that you activated the virtualenv before you installed Flask and your other dependencies -
$ virtualenv env
$ source env/bin/activate
$ pip install flask
Then when you're done working, make sure to deactivate the environment -
$ deactivate
Finally, when you want to start working again, navigate to your project directory and reactivate the environment -
$ source env/bin/activate
At this point, I would just remove the virtualenv and start over.
Hope that helps!