When I trying to activate virtual environment using venv, pipenv and conda I always getting this error:
venv/bin/activate:41: parse error near `deactivate'
There's content of activate file:
Activate
I had exacly same issue. It was conflicting alias in my case.
I had alias fi="flatpak install --user" in my ~/.zshrc.
When I commented that, command worked like this:
$ fi
zsh: parse error near `fi'
and source venv/bin/activate worked correctly
Related
hi i have installed virtualenv python library to manage my env doing all the setup but when i use the following command to open my env that happen
francesco#AirdiFrancesco ~ % workon
zsh: command not found: workon
but when i run this code before workon don't give me problems
export WORKON_HOME=~/Envs
VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /opt/homebrew/bin/virtualenvwrapper.sh
now i have tried to add this three line to my ~/zshch file but doesn't work. where i need to put this code in my bash?
is there a way to easily switch from conda environments to my system's native python environment? When I have conda activated, and I run bash or exec bash it doesn't seem to work, and when I run python it uses conda's python and it's not using the system python path. The only way I've been able to get this to work is by restarting the terminal entirely. Is there a faster way to do this?
(I've actually removed the conda init block from my ~/.bashrc and I run it manually every time I want to use conda's python.)
You have two options:
Just deactivate the base environment:
(base) $ conda deactivate
$
Configure your conda to not activate the base environment on startup.
(base) $ conda config --set auto_activate_base false
<restart shell>
$
# use the system python
$ python
# to use conda you'll need to activate it first
$ conda activate
(base) $ python
The conda command you're looking for is deactivate.
Suppose you have activated the myproject environment.
$ conda deactivate
Now your environment is base, as seen by which python,
or conda info --envs.
$ conda deactivate
Now you're not using conda at all, and which python shows the system
interpreter, likely /usr/bin/python.
This may be a bit of a hack, but what about adding an alias pointing to the system python before the conda block in .bashrc? Assuming you don't want to use "conda deactivate" and lose the environment completely.
alias syspython=`which python`
# >>> conda initalize >>>
...
You should then be able to use the system python in a conda env like so:
syspython file.py ...
I've tried everything I've seen on SO to get this to work, but so far everything fails. Using macOS Big Sur 11.6, bash in Terminal (not zsh).
I'm trying to create a setup file and execute with sh setup.sh that will setup the env, install python, and then activate it. Nothing fancy. Doing it manually works fine, but once I put it in a shell script, it won't work. I'm running this script from inside an empty project folder.
Current script:
conda create -n MASTER python=3.8.5 -y
conda activate MASTER
Yeah, it's that simple to start with. I commented out the other pip installs until this works properly.
I tried running: bash -i setup.sh but it still does not activate. I get no errors but I'm still stuck in (base).
I tried using source: source /opt/anaconda3/etc/profile.d/conda.sh at beginning of script and/or before activate, still doesn't work. No errors again, but stuck in (base).
I tried using: eval $(conda shell.bash hook) at the start of script and before I try to activate the env, but it fails. This time I get the error:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
But if I run conda init bash (in Terminal or in the script itself), it outputs:
no change /opt/anaconda3/condabin/conda
no change /opt/anaconda3/bin/conda
no change /opt/anaconda3/bin/conda-env
no change /opt/anaconda3/bin/activate
no change /opt/anaconda3/bin/deactivate
no change /opt/anaconda3/etc/profile.d/conda.sh
no change /opt/anaconda3/etc/fish/conf.d/conda.fish
no change /opt/anaconda3/shell/condabin/Conda.psm1
no change /opt/anaconda3/shell/condabin/conda-hook.ps1
no change /opt/anaconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change /opt/anaconda3/etc/profile.d/conda.csh
no change /Users/liquidRock/.bash_profile
No action taken.
I tried doing /opt/anaconda3/bin/conda activate MASTER which also prompts me to do conda init bash.
Even tried adding #!/bin/bash to the top of the file just in case, but no dice.
Thanks to #fravadona for the simplest of solutions.
Simply executing the script with source instead of sh. 🤦🏻♂️
Final setup.sh script (with my preliminary pip installs):
# env & python
conda create -n MASTER python=3.8.5 -y
conda activate MASTER
# pip installs
pip install cmake
pip install --upgrade pip setuptools wheel
pip install opencv-python==4.2.0.32
pip install argparse
pip install datetime
pip install colorama
pip install python-dotenv
pip install python-dotenv[cli]
Executed thusly:
$ source setup.sh
Anaconda creates the env, installs python and dependencies, activates the env, then pip installs the additional dependencies.
Still not sure why it won't work by adding other things to the shell script, but this is still a great, simple solution. And yes, I am a novice with this stuff.
I added this to my .bash_profile
export WORKON_HOME= sudo $HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Then it gives me this message
NOTE: Virtual environments directory /Users/rawad/.virtualenvs does not exist. Creating...
mkdir: /Users/rawad/.virtualenvs: Permission denied
What should I do to fix it? I tried a lot of things online, but nothing work.
As others pointed out, the code for .bashrc seems to be invalid. Please refer to the official virtualenvwrapper documentation. WORKON_HOME should refer to the base directory you want to store environments in (not a command). e.g.:
export WORKON_HOME=~/virtualenvs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
Note: I wouldn't recommend using virtualenvwrapper anymore. Just create relative virtual environments and activate them. e.g.:
$cd /path/to/python-project
$python -m venv .venv
$source .venv/bin/activate
I am trying to create alias from pip to pip3.
I followed this tutorial exactly.
The section
Don't forget to update pip to pip3! is what I followed.
I installed python3 through brew, and which pip3 gives me /usr/local/bin/pip3
I checked ~/.bashrc and it has the line below correctly.
alias pip= /usr/local/bin/pip3
But when I do source ~/.bashrc to apply the new code, it gives me
-bash: alias: /usr/local/bin/pip3: not found
What am I doing wrong?
The spacing is very important in bash.
Change
alias pip= /usr/local/bin/pip3
to
alias pip=/usr/local/bin/pip3
It will work fine.