I want to install a package which is just used in one project.
So I create a virtual env and install it
python -m venv .venv --system-site-packages
python -m pip install my_package
Then I want to debug it with jupyter.
The problem is It seems I have to either install another jupyter in my virtual env ( quite large):
pip install jupyter
jupyter notebook
or register this env as a kernel to user:
python -m ipykernel install --user --name my_test_env
in this case, this env will list in my global kernel list but I won't use if for any other project. And delete the project folder will leave a broken kernel in global jupyter.
Is there any way to register a kernel just for current project?
Related
Below step by step answer:
To install virtual environment using use below pip command:
py -m pip install --user virtualenv
Then create new environment:
py -m venv projectName
Then you have to activate your virtual environment:
.\projectName\Scripts\activate
Once done with activating virtual environment, You’ll see “(myproject)” next to the command prompt.
To install virtual environment using use below pip command:
py -m pip install --user virtualenv
Then create new environment:
py -m venv projectName
Then you have to activate your virtual environment:
.\projectName\Scripts\activate
Once done with activating virtual environment, You’ll see “(myproject)” next to the command prompt.
I tried some guides that I found but nothing works. I need this virtual env for a telegram bot. I| use Visual studio code
How to install virtualenv:
Install pip first
sudo apt-get install python3-pip
Then install virtualenv using pip3
sudo pip3 install virtualenv
Now create a virtual environment
virtualenv venv
you can use any name insted of venv
You can also use a Python interpreter of your choice
virtualenv -p /usr/bin/python2.7 venv
Active your virtual environment:
source venv/bin/activate
Using fish shell:
source venv/bin/activate.fish
To deactivate:
deactivate
Create virtualenv using Python3
virtualenv -p python3 myenv
Instead of using virtualenv you can use this command in Python3
python3 -m venv myenv
Its looks like your problem is activating the virtual environment.
source env/bin/activate
or just type activate in your terminal.
If you are using windows try:-
env\Scripts\activate.bat
Install. To create a virtual environment, use the following command, where .venv is the name of the environment folder:
python -m venv .venv
Activate. When you create a new virtual environment, a prompt will be displayed to allow you to select it for the workspace.
This will add the path to the Python interpreter from the new virtual environment to your workspace settings. That environment will then be used when installing packages and running code through the Python extension.
You can switch environments at any time at the bottom left corner of VS Code window or using the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
I have installed my needed packages (dependencies) in the global system environment instead of my virtual environment (virtualenv) because i have used the command pip install <package-name> outside of the virtual environment.
So i want to know how can i make a list out of them and install them in any of my virtualenvs?
This is useful in a case that anyhow you have installed some packages (dependencies) in your global system environment instead of your virtualenv, by mistake.
For example by using the command "pip install", not "pipenv install" (outside of virtual environment).
So the solution is:
In the global system environment (outside of any virtualenv), create a "requirements.txt" file from all of your installed packages:
$ pip freeze > requirements.txt
Import installed dependencies from the created "requirements.txt" file to the Pipfile by running the below command in the root that the above created file "requirements.txt" exist; but first check:
a) If Pipfile not exist:
$ pipenv install
b) If Pipfile do exist (i.e. already created virtualenv):
$ pipenv install -r requirements.txt
Then your package listing files "Pipfile" & "Pipfile.lock" would be updated and locked.
But I personally recommend that for avoiding this problem to happen, always use the command
$ pipenv install
instead of $ pip install.
You can create file in your global system environment the format of this file is like following:
my_backages.txt
$ pip install -U Flask-SQLAlchemy
$ pip install --upgrade
$ pip install flask
then you can use pipfile as next :
$ pip install -r my_backages.txt
I'm trying to create an virtual environment with Python 3.7, using the pipenv command. Trying to run pipenv install --python=python3.7 gives the error below:
pipenv install --python=python3.7
loading virtual environment veriables
Creating a virtual environment for this project
Using path/to/python3.7 (3.7.0) to create virtualenv...
Creating virtual environment... Already using interpreter path/to/python3.7
New python executable in /home/user/.local/share/myproject/bin/python3.7
Not overwriting existing python script /home/user/.local/share/myproject/bin/python (you must use /home/user/.local/share/myproject/bin/python3.7)
failed to create a virtual environment.
How can I create a virtual environment using pipenv?
There are several ways to create a virtual environment, try with these commands
sudo pip3 install virtualenv
# After this installation
python -m virtualenv vnvname
or
python3 -m virtualenv vnvname
It will create a virtual environment
You can use the virtualenv command
virtualenv -p python3 envname
Update :
pip install --upgrade virtualenv
I had this error in PyCharm using Kubuntu (Linux)
Failed to create virtual environment
Found the answer in here Create a Python3 virtual environment to just run this command
sudo apt-get -y install python3-dev python3-pip libkrb5-dev
I currently use a Mac. I recently created a new python virtual environment and installed jupyter. When I activate jupyter notebook within the virtual environment, it says it cannot find any python kernels. I have another virtual environment that also has jupyter installed and it works perfectly fine. Can anyone help? Also, I'm not sure where the Kernels are even located on my machine. Library/Jupyter only has a runtime folder.
I need to do 2 things to get this to work:
conda install -y ipykernel
python -m ipykernel install --user --name myenv
Kind of frustrating and I never see it mentioned much in the docs. Jupyter set up remains a pretty painful process in my opinion. This is from beginning to end, if it helps anyone:
conda create -n myenv python=3.7
conda activate myenv
conda install -y -c conda-forge jupyterlab
conda install -y -c anaconda jupyter
conda install -y ipykernel
python -m ipykernel install --user --name myenv
Try installing nb_conda in your environment, by going to your command line conda activate your environment and conda install nb_conda. Make sure you also have ipykernel installed in your environment, then deactivate and reactivate your environment and try again.