I want to use a virtualenv for my python3 project:
did virtualenv -p python3 venv to install it.
when doing . venv/bin/activateit doesn't activate the venv (I'm able to use all my lib's in standard path) also no (venv) before prompt. There is also no error, it just gives me a new line.
source venv/bin/activate gives me the same result.
Interestingly my VSCode detects when virtualenv -p python3 venv is run and asks if I want to change the environment.
Related
I'm in the middle of switching from VS Code to Atom and I'm trying to set up a virtual environment for my python project.
It was pretty easy to do in VS Code, I'd run the following script and it would automagically start using the new env (with all the required packages) when I'd run the script:
python3 -m venv my_env
source my_env/bin/activate
pip3 install -r requirements.txt
Now I'm trying to set up Hydrogen to work the same way. When I run lines of code inline with Hydrogen, I want them to be run in a virtual environment that has the imported modules I need from a requirements.txt file.
I was able to install the python3 kernel with the following commands:
python3 -m venv my_environment_name # create a virtual environment
source my_environment_name/bin/activate # activate the virtual environment
python -m pip install ipykernel # install the python kernel (ipykernel) into the virtual environment
python -m ipykernel install
And Atom is able to see it:
Screenshot
However, I'm still puzzled as how to install my dependencies into the kernel. And if I do install my dependencies there, I don't want my next python projects to have all those modules in there. I'd love to have the fresh-slate that virtual environments promise.
Any help here would be appreciated. Has anyone had experience setting up a virtual environment that can be used by the Hydrogen package?
Ok, after some more experimentation, I was able to connect to a kernel that I had installed my requirements.txt into.
Here are the steps I took:
python3 -m venv env
source env/bin/activate
# make sure requirements.txt has ipykernel in it
pip3 install -r requirements.txt
python3 -m ipykernel install --user --name=env
Then in Atom, press cmd-shift-p and find Hydrogen: Update Kernels.
Or manually Packages->Hydrogen->Update Kernels
After, I was able to use the kernel by doing cmd-shift-p again and selecting Hydrogen: Start Local Kernel and selecting env.
When I would run import statements via Hydrogen (selecting them and pressing cmd-enter), they would now know what to import! Horray!
Windows Version.
This is the windows version of the excellent answer by Tim Estes. Without the use of requirements.txt in case some folks such as myself would like to install ipykernel separately. (Thanks so much Tim, it saved me a ton of time)
python -m venv env
env/bin/activate
pip install ipykernel
python -m ipykernel install --user --name=env
Similar to Tim's answer, go ahead and update kernels at Atom.
Packages->Hydrogen->Update Kernels
I have this line in my .envrc
source python3-venv/bin/activate
I basically created a python3 venv inside the folder where the .envrc is located.
However even through the .evnrc is executed (e.g. all now env variables are set correctly when I enter this directoy), the venv is not activated.
When I do which python3, it shows /usr/local/bin/python3 instead of <path to my current folder>/python-venv/bin/python3
If I run the source line manually, the bash prompt will switch to (python3-venv) my-workstation:working-folder antkong$ as expected.
How can I get the python-venv correctly activated?
I am running it in MacOS Mojave.
I removed the venv then rebuild the venv
python3 -m venv python3-venv
It seems to fix the issue.
I have python in ConEMu loaded and am trying to creating a virtual environment to work in.
I used
pip3 install virtualenv --user
and it said that virtualenv was usccessfully installed, however then I try to
virtualenv .venv
and i get the error message
bash: virtualenv: command not found
wondering if anyone else has run into this problem
virtualenv is built into python 3, and called venv. You don't need to install anything with pip.
You can make a virtualenv in python 3 like this:
python3 -m venv ve
On Mac, if I simply open a new terminal window and run:
python --version
I get:
3.6
but if I do this:
virtualenv venv && source venv/bin/activate
and then, in that environment, I run :
python --version
I get:
2.7
I need virtualenv to run 3.6. How do I do that?
This :
/usr/bin/python
is 2.7 but this:
/usr/local/bin/python
is 3.6. The path for my normal user has /usr/local/bin come up before /usr/bin/. Is virtualenv running as someone else? How do I control its path?
I ran this:
virtualenv -p /usr/local//Cellar/python/3.6.5/bin/python3 venv
but then I do this:
virtualenv venv && source venv/bin/activate
and I'm running in an environment with 2.7.
On Python 3 you don't need virtualenv script anymore, you should just use the venv module included with standard lib:
python3 -m venv myvenv
But if you really want to keep using the old virtualenv script, you can - specify the interpreter explicitly with the -p option:
virtualenv -p /path/to/python3 myvenv
The easiest way is to change python globally to Python3 as I think you're using it more often than Python 2.7 (or hopefully always). To achieve this, add the following line of code at the end of your .bash_profile:
alias python='python3'
virtuanenv is using /usr/bin/python, hence it should work now.
If you don't want to change it globally, than you should use the following command to create your Python3.6 virtual environment:
python3 -m venv venv
or the explicit Python version if you have multiple Python3 versions installed:
python3.6 -m venv venv
On more suggestion at the end: I recommend you to read something about pipenv as it's the new recommended way to handle virtual environments and your whole package management at once. It's super easy and fixes a lot of common issues. Here's a nice article from realpython.com on that topic.
Hope I could help you. Have a nice day.
I am able to install python module in virtualenv but it is accessible outside the virtualenv as well. How to restrict its usage in virtualenv?
I went to the virtualenv path and then typed activate. It got activated as I could see root at the beginning.
And then I used the command pip install module_name
Activated the virutal env and then deactivated it.
When I activated the virtual env I was able to import the module.
When I deactivated it still the module was easily imported.
I assume the module was installed globally. I want it to be installed only in virtual env and should not be accessible outside.
The virtualenv tool is basically used to isolate the dependencies required for multiple projects. The python version installed within virtualenv won't be visible in the global directory.Try following the below steps properly in the virtualenv.
pip install virtualenv
cd my_project_folder
virtualenv venv
virtualenv -p /usr/bin/python3.5 venv
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
source venv/bin/activate
[Vitualenv Link:][1]
http://docs.python-guide.org/en/latest/dev/virtualenvs/
virtualenv -p /usr/bin/python3 name_of_venv #to create venv
source name_of_venv/bin/activate #to activate venv
pip install module_name #to install module
It is not visible from the outside. As soon as you type deactivate it is no longer importable.