If I run the command:
pipenv shell
in my Mac shell, everything works fine and a new virtual environment is created and activated:
.../django_celery_rabbit_flower$ pipenv shell
Launching subshell in virtual environment...
bash: parse_git_branch: command not found
.../django_celery_rabbit_flower$ . /.../django_celery_rabbit_flower-rEt8HW1V/bin/activate
bash: parse_git_branch: command not found
(django_celery_rabbit_flower) .../django_celery_rabbit_flower$
but a bash error is displayed:
bash: parse_git_branch: command not found
I do not understand where it come from. Any idea?
UPDATE
Jen answer trigger a little thought. I have checked my ./bash_profile and I can see the line:
export PS1="\[\033[36m\]\u\[\033[m\]#\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$(parse_git_branch)\$ "
This shows the git branch on the bash prompt. So I believe vscode uses this settings. The folder I am working on is not a git folder. Can I write an if statement to avoid the error being displayed when running the python virtual environment?
Instead make sure that the command does actually exists before running it.
PS1="...."'$(if hash parse_git_branch >/dev/null 2>&1; then parse_git_branch; fi)'"..."
Related
This question already has answers here:
Virtualenv Command Not Found
(31 answers)
Closed 1 year ago.
I am trying to create a python virtual environment for Django in ubuntu 20.04 using jenkins execute shell. I have seen a solution here at askubuntu and trying to reproduce this solution but getting the following error in console output:
Running as SYSTEM Building in workspace
/var/lib/jenkins/workspace/python_virtual_Env [python_virtual_Env] $
/bin/bash /tmp/jenkins8922469990510149005.sh ModuleNotFoundError: No
module named 'virtualenv.seed.embed.via_app_data'
/tmp/jenkins8922469990510149005.sh: line 3: cd: virtual_django1/bin:
No such file or directory
/var/lib/jenkins/workspace/python_virtual_Env
/tmp/jenkins8922469990510149005.sh: line 6: activate: No such file or
directory Build step 'Execute shell' marked build as failure Finished:
FAILURE
Below are my commands which i have used in jenkins execute shell:
#!/bin/bash
virtualenv virtual_django1
cd virtual_django1/bin
pwd
dir
source activate
I have ran the above commands with and without #!/bin/bash but still error persist. How can i get rid off this error in console and get able to create as well activate python virtual environment using jenkins execute shell.
I am able to resolve this issue by creating a virtual envirnoment with another command rather than virtualenv. Below is the exact shell commands which will be needed to create and activate the virtual envirnoment for python using jenkins shell:
#!/bin/bash
sudo apt install python3.8-venv
python3 -m venv Virtual_Django
cd my_env/bin
pwd
dir
source activate
I haven't been able to find a similar question, but I can't imagine this is an issue that comes up too much.
At my workplace I've decided to switch over to a full Linux experience by using Cygwin, over what I was previously using, Git Bash.
The only slight drawback is that we have a script written in Ruby that deploys changes to our site. I can run this from my Git Bash terminal no problem, but not Cygwin as there doesn't seem to be a Ruby installation on here. I've learned about sending standard output to other terminal windows, but I've only been successful when both terminals have been the same shell.
What I'd like to do is the following:
1. Type a command into Cygwin that opens a Git Bash terminal and automatically runs ./deploy.sh on that Git Bash terminal upon opening.
2. If possible, also pass in an argument in the same command, that the script expects upon running. (In this case it's whether we want to deploy to our staging or production server).
Is this possible? So far I can get what looks to be a Git Bash terminal to open and prompt me for the server, but when I enter it, it does not work. I get an error with regards to a command within the script not being found. Thing is, running this same ./deploy.sh script in a Git Bash terminal that I open myself works perfectly as it always has. The Git Bash terminal that is being opened by Cygwin does not appear to have all of the capabilities of a Git Bash terminal I open 'the normal way'.
The command I am running so far from Cygwin is as follows:
/cygdrive/c/'Program Files'/Git/git-bash.exe "./deploy.sh"
I understand there is probably a way of getting this to work by installing Ruby via Cygwin but I'd like to mess around with my work environment as little as possible in case I somehow affect my ability to deploy my work... and besides, Git Bash definitely runs this script without an issue so I can't see why I would need a duplicate installation.
Many thanks!
I try to open terminal in XFCE and activate python3 virtualenv using the following line in a bash script:
xfce4-terminal --working-directory=$HOME/path/to/project --maximize \
-e 'bash -c "source $HOME/path/to/project/venv/bin/activate; bash"'
The strange thing is that the virtualenv gets kind of activated since:
which python
shows the correct path to the virtualenv directory and the project seems to be working fine.
However I don't see the (venv) to the left from the shell prompt. Moreover, when I enter deactivate it complains that no such command can be found.
Is there a proper way to solve this problem?
I created a bash shortcut for this in my /Users/username/.bash_profile (I use mac; on linux use Users/username/.bashrc instead).
function pcd() {
cd /Users/username/Code/"$1"_env/"$1"
source ../env/bin/activate
atom -a .
}
Where project_env is the root folder, which contains the venv, and the project folders (project folder is where code goes)
to execute this simply call pcd project
I don't know much about bash, so I can't really tell you why your code doesn't work.
Also, make sure you open a new terminal window after saving this.
I can activate my python virtual environment from it's folder by entering . bin/activate. I'd like to instead type a single word alias, such as shazam, from the home folder (or anywhere else) that activates the environment, changes to my master project folder, and lists my projects.
I tried creating an alias in .bashrc that pointed to an .sh file containing:
cd ~/path-to-virtual-environment
. bin/activate
cd ~/path-to-master-project-folder
ls -a
I was getting a permission denied error, so I ran chmod u+x <script file>. The script now runs, but the VE does not activate and while the project folders are listed, the shell is not in the master project folder. I would appreciate some guidance. Thanks.
Recreate all your environments in ~/.virtualenvs and install virtualenvwrapper. The command to activate an env is workon shazam. Command line completion is supported.
Now about your problem: you've tried to activate an environment in a shell script. That doesn't work because shell scripts run with another shell and env activation change their environments, not the current. I.e., the environment briefly activated but then at the end of the script the new shell exits and the environment deactivated.
There are two ways to overcome this.
Use aliases or shell functions instead of scripts — they are the only way to change the current shell's environment.
Run interactive shell at the end of your script (exec $SHELL). It inherits activated environment and gives you a command prompt. To deactivate simply exit the shell (exit or [Ctrl]+[D].).
I am currently working on this: https://mozilla.github.io/ichnaea/install/devel.html#prerequisites and have been a bit stuck since they recommend working with Linux/Mac but I am limited to Windows. I tried getting their steps to work with Git Bash, Powershell, and Command Prompt but to no success. I am currently trying Cygwin to see if it would work however I am running into some issues. I currently run docker-machine env default and see the output:
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="..."
export DOCKER_CERT_PATH="..."
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default)
When I attempt to run the command to configure the shell, eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default), I get an error saying: -bash: C:\Program Files\Docker Toolbox\docker-machine.exe: command not found.
This is different than Git Bash, Powershell, and CMD since when I ran the respective commands on those shells there were no issues at all and it led me to successfully move on to the next steps. Is there any reason why I am getting this command not found error on Cygwin, and what should I do to fix it?
Thanks for reading
Adding a cygpath invocation to convert the executable path:
eval "$("$(cygpath -u "C:\Program Files\Docker Toolbox\docker-machine.exe")" env default)"