I've created a pipenv environment and now I'm creating a shell script called bootstrap.sh to activate it and run a flask server, but the following line is producing an error
bootstrap.sh reads as follows
#!/bin/sh
...
source "$(pipenv --venv)\\Scripts\\activate"
...
Running simply pipenv --venv returns C:\Users\johng\.virtualenvs\cashman-flask-project-2vwc8e6G
But executing the shell script returns a No such file or directory error
$ source bootstrap.sh
/Scripts/activate: No such file or directoryask-project-2vwc8e6G
This is in the vsCode bash terminal on Windows 10. The file certainly exists and can be navigated to, so what is causing this?
Related
My .bat file looks like this:
cd somewhere
virtualenv/Scripts/activate
cd somewhere_else
set FLASK_APP=flask_app.py
python -m flask
flask run
However the .bat stops after the second line (virtualenv/Scripts/activate).
How can I make it keep executing the following lines ?
I'm trying to create a bat file to open windows terminal, activate an environment and run a server. After some attemps the best I've got is this:
wt.exe cmd -NoExit -c "c:\Users\me\Desktop\'myProyectVirtualenv'\virtualenv\Scripts\activate.ps1;cd C:\Users\me\Desktop\myProyect\;python manage.py runserver"
But windows terminal activate the environment in a tab and in other tab throw this error:
[error 0x80070002 when launching `"C:\Users\me\Desktop\myproyect\;python manage.py runserver"']
I think that maybe the command after the environment activation is not properly 'passed' to the environment... but really I don't know how to solve it.
-NoExit -c both look like powershell flags, not cmd ones. That might be a place to start.
I'd recommend just taking the entire script you've got there:
c:\Users\me\Desktop\'myProyectVirtualenv'\virtualenv\Scripts\activate.ps1;cd C:\Users\me\Desktop\myProyect\;python manage.py runserver"
and putting it into a .bat file like:
powershell -f c:\Users\me\Desktop\'myProyectVirtualenv'\virtualenv\Scripts\activate.ps1
cd C:\Users\me\Desktop\myProyect\
python manage.py runserver"
then running that with wt.exe foo.bat
To run my python tests I created a freestyle project in Jenkins and wrote a script like this:
. .env/bin/activate
pip install pytest
pytest --alluredir='FINAL/ws/allure-results' ./FINAL/autotests
But the build crashes with the "Can't open" error:
You can try by adding #!/bin/bash in the first line of the script step and then try to execute.
In the user site .pth files are processed once at interpreter startup:
$ echo 'import sys; sys.stdout.write("hello world\n")' > ~/.local/lib/python3.8/site-packages/hello.pth
$ python3.8 -c ""
hello world
And it's the same behaviour in the system site, e.g. /usr/local/lib/python3.8/site-packages/.
But in venv they are processed twice:
$ rm ~/.local/lib/python3.8/site-packages/hello.pth
$ /usr/local/bin/python3.8 -m venv .venv
$ source .venv/bin/activate
(.venv) $ echo 'import sys; sys.stdout.write("hello world\n")' > .venv/lib/python3.8/site-packages/hello.pth
(.venv) $ python -c ""
hello world
hello world
Why are path configuration files processed twice in a virtual environment?
Looks like it all happens in the site module (not so surprising). In particular in the site.main() function.
The loading of the .pth files happens either in site.addsitepackages() or in site.addusersitepackages(), depending in which folder the file is placed. Well more precisely both these function call site.addpackage(), where it actually happens.
In your first example, outside a virtual environment, the file is placed in the directory for user site packages. So the console output happens when site.main() calls site.addusersitepackages().
In the second example, within a virtual environment, the file is placed in the virtual environment's own site packages directory. So the console output happens when site.main() calls site.addsitepackages() directly and also via site.venv() a couple of lines earlier that also calls site.addsitepackages() if it detects that the interpreter is running inside a virtual environment, i.e. if it finds a pyvenv.cfg file.
So in short: inside a virtual environment site.addsitepackages() runs twice.
As to what the intention is for this behavior, there is a note:
# Doing this here ensures venv takes precedence over user-site
addsitepackages(known_paths, [sys.prefix])
Which, from what I can tell, matters in case the virtual environment has been configured to allow system site packages.
Maybe it could have been solved differently so that the path configuration files are not loaded twice.
I am having an issue via an apache Nearly Free Speech server (I have been following the NFS guide via this link: https://blog.nearlyfreespeech.net/2014/11/17/how-to-django-on-nearlyfreespeech-net/. I have created a run-django.sh file to properly run the application which also opens a virtualenv (I have named the folder 'venv'). These are the contents of my run-django.sh file:
#!/bin/sh
. venv/bin/activate
exec python3 manage.py runserver
On the current step of the guide I am attempting to run the run-django.sh as follows:
[questionanswer /home/protected]$ ls
question_answer run-django.sh venv
[questionanswer /home/protected]$ cd question_answer/
[questionanswer /home/protected/question_answer]$ ../run-django.sh
.: cannot open bin/activate: No such file or directory
How is this not detecting my directory of 'venv/bin/activate' ?