I have set up a python virtual environment with pyenv on Linux Now I would like to create a Django project in PyDev with one of these virtual environments. However, I cannot figure out how to locate my virtual environment, since running which python in the virtual environment only gives me the generic /home/rbu/.pyenv/shims/python.
First find your virtualenv directory with
pyenv prefix <venv-name>
The python executable of the virtualenv should be <path>/<to>/<venv>/bin/python.
Now set up a new interpreter in Eclipse Preferences>PyDev>Interpreters>Python Interpreter using the location of the executable and a adequate name.
After that you can start a new Django Project via File>New>Project>Pydev>PyDev Django Project. Choose your predefined interpreter.
The Django Project should now work inside the virtualenv. For installing new packages it is probably easiest to just activate the virtualenv in the terminal with
pyenv activate <venv-name> and pip install the package.
Related
Error Message
I am struggling to install Django to my new project using pipenv, it keeps telling me to run another virtual environment rather than actually installing Django.
I tried to do what it says to using the other virtual env but it still won't work.
You get that all wrong.
"The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. A virtual environment is created on top of an existing Python installation, known as the virtual environment’s “base” Python, and may optionally be isolated from the packages in the base environment, so only those explicitly installed in the virtual environment are available.
When used from within a virtual environment, common installation tools such as pip will install Python packages into a virtual environment without needing to be told to do so explicitly."
pip is python package manager and there for tool for installing modules such as Django. If you are running linux you can use following commands
-> cd storefront
-> python -m venv venv (create new virtual environment name: "venv")
-> . venv/bin/activate (to activate virtual environment)
-> pip install django (to install Django modules)
I try to install a package with pip in a virtual environement previously created with venv. The Python version is managed through pyenv. I don't want to use pyenv to create the virtual environment.
The project is set up this way. To the project empty directory, I added a .python-version containing the version 3.8.2. Then I created my virtual environement using python -m venv .venv. Then I activated the environement using source .venv/bin/activate. Now the command line starts with a (.env). However, when I try to install some package with pip install some-package, the package ends up in {pyen_home}/versions/3.8.2/lib/python3.8/site-packages, instead of the virtual environment.
What's irritating is that I'm almost certain that I did manage to install package in the virtual environment that way before, but not anymore, so I don't see what I'm missing.
Content of your .python-version should be .venv.
As far as I know you should not create this file by yourself. It generated when you run pyenv local .venv. And venv activates automatically.
Also proper way to create virtual environment is pyenv virtualenv {python-version} {venv-name}. Read the docs carefully.
I installed Anaconda last night. Previously, I was using pip and the virtual environment GUI in PyCharm to setup and manage my virtual environments.
Now I know I can create a new environment in my project structure by navigating to the project then using
conda create --prefix ./myenv mypackage1 mypackag2
That's really cool. But how do I deal with the fact that PyCharm has already created a virtual environment using virtualenv? And for older projects that I'm still working on, how do I transition from using conda to manage those project environments (also made by PyCharm and populated with pip)?
For example:
How do I use conda to install hub inside a pre-existing non-conda
environment?
How do I even call conda from an activated non-conda environment,
since when I try it doesn't register conda's existence?
Note: PyCharm just calls virtualenv to create a virtual environment. This question is not about PyCharm.
I am running Pycharm 2019.3 on Linux Ubuntu 18.04 LTS. I have created a virtual environment for my Pycharm project from within the IDE. I am able to access the packages from the virtual environment when I run programs from within the IDE. However, if I activate the virtual environment created from within Pycharm from the terminal (using source venv/bin/activate, resulting in the (venv) prefix on the command line), the packages I added to the virtual environment can no longer be found. Why is this? The (venv) prefix makes me think that I have successfully activated the virtual environment. What can I do to use this virtual environment outside of Pycharm?
I think this is because pycharm has created a virtual environment in a different location. I think you can check both the locations with echo $VIRTUAL_ENV and check if they are the same.
when I pip install a package it gets insalled on my macs library. I am using pycharm whih allows me to click on a package like a hyperlink. And instead of going to my site-packages in my virtualenv it's going to my macs library which is
/Library/Frameworks/Python.Framework/Versions/3.5/lib/python3.5/site-packages/gdata/youtube/
when it should be
myproject/lib/python3.5/site-packages/gdata/youtube/
why is that.
You should activate your virtual environment to install packages on that. In Pycharm you can do it like this:
Go to File > Settings > Project > Project Interpreter
Now you have to select the interpreter for this project. Browse or select the interpreter from drop-down if available. In your case this should be:
myproject/lib/python3.5
I am using Pycharm community edition on Ubuntu. But the
process should be similar in Mac.
I think you want to create a virtual environment for your project.
Install this tool virtualenv.
$ pip install virtualenv
Then create your project's folder
$ cd my_project_folder
$ virtualenv venv
This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named venv.
Source
https://github.com/pypa/virtualenv
For further knowledge read
https://realpython.com/blog/python/python-virtual-environments-a-primer/
You should install your virtual environment and then run pip within that environment. So, for example, I use Anaconda (which I thoroughly recommend if you are installing alot of scientific libraries).
To activate the environment "hle" I type in:
source /Users/admin/.conda/envs/hle/bin/activate hle
Once I've done this the pip command will reference the virtual environment location and not the standard mac location. So, when I install "mypackage" as follows:
pip install mypackage
It subsequently installs files in the virtual folder and not in the usual mac system folders.
You can find out about the Anaconda virtual environment (and download it) over here: http://conda.pydata.org/docs/install/quick.html but other virtual environments (like Virtualenv) work in the same way.