Navigating to Pycharm Virtual Environment - python

I created a new Python project and a virtual environment using Pycharm, however I am unable to navigate to the virtual environment using Ubuntu terminal. Could anyone share how I could enter the virtual environment through the Ubuntu terminal and run python files with the packages available in that specific environment.
My pycharm terminal shows this by default:
(conditional_slim_gan) arsh#Arsh:~/Desktop/machine learning/Outlier_dataset$

To activate the created virtual environment, run the following command in ubuntu terminal:
source /Desktop/machine learning/Outlier_dataset/bin/activate

Related

Failed to create a virtual environment using pipenv inside a conda Python 3.8.3 environment on Windows

System and environment details:
Anaconda based python environment on a Windows 10 PC
conda 4.8.5
Python 3.8.3
pipenv version 2020.8.13
I wish to launch a virtual environment for a new project, install the dependencies inside that virtual environment and run the code. The project is located in the code/ directory on my PC. I installed pipenv in my PC for creating a virtual environment using pip install pipenv. To create a virtual environment using pipenv, I executed the command pipenv shell from the root of my project directory (code) and got the following output.
$ pipenv shell
Creating a virtualenv for this project...
Pipfile: C:\Users\myPC\code\Pipfile
Using C:/Users/myPC/Anaconda3/python.exe (3.8.3) to create virtualenv...
[== ] Creating virtual environment...FileNotFoundError: [Errno 2] No such file or directory: 'c:\\users\\myPC\\anaconda3\\Lib\\venv\\scripts\\nt\\python.exe'
Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]:
Failed to create virtual environment.
The python executable being pointed to in the output above i.e., C:/Users/myPC/Anaconda3/python.exe (3.8.3) is the place where Anaconda is installed in my PC, so this seems to be fine.
However, I do not understand what file it is looking for in the last line of the output.
I was able to solve this issue myself by referring the solution mentioned in this github issue. Although, this seems to be a workaround for the moment but nevertheless, it works.
I manually copied the python.exe and pythonw.exe from C:/Users/myPC/Anaconda3/ directory into c:\users\myPC\anaconda3\Lib\venv\scripts\nt\

Python 2.7 Script in Virtual Environment

I am running a Python 2.7 script that has specific dependencies/libraries (contained in a virtual environment) using anaconda prompt. Is there a way to run the script using code in a python 3 .py file in a different environment? Something like a library that allows me to open anaconda prompt in a specific environment (to then run the python 2.7 script). I couldn't seem to find it online. Any pointers would be appreciated.
Well you can select the environment from the drop-down box in the Anaconda Navigator home page if you have your virtual environment in Anaconda itself.
Or you can use
conda activate env-name
If you have your base conda in your terminal as default or else activate using
source ~/.bash_profile
then run
conda activate env-name
Hope this helps.

Virtualenv environment would not activate in CMD on Windows 10

I have tried this with python 3.7 as well as python 3.8.
Installed virtualenv with pip and then created a virtual environment with following command:
virtualenv abc
I cd to the Scripts folder and run the following command and please enter... the response is on the very next line:
C:\Users\user\abc\Scripts>activate.bat
C:\Users\user\abc\Scripts>
As you can see nothing happens... virtual environment does not get activated. I have also tried "Scripts\activate" from the environment folder.
I tried it with another windows machine that I have and its working fine there.
Any ideas?

How do I fix Django changes made outside of my virtual environment?

I am new to Django and new to the virtualenv scene.
I have been working on a Django project for a couple of days and completely forgot to activate my venv on my second day.
I am using this tutorial to guide me and I have been working from within my activated environment up until this point....
Is it enough to just re-run manage.py after activating my venv?
Activating a virtual environment
Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH.
On macOS and Linux:
source env/bin/activate
On Windows:
.\env\Scripts\activate
You can confirm you’re in the virtual environment by checking the location of your Python interpreter, it should point to the env directory.
On macOS and Linux:
which python
.../env/bin/python
On Windows:
where python
.../env/bin/python.exe
Leaving the virtual environment
If you want to switch projects or otherwise leave your virtual environment, simply run:
deactivate
If you want to re-enter the virtual environment just follow the same instructions above about activating a virtual environment. There’s no need to re-create the virtual environment.
For Django
After active your virtual environment you need to run Django development server. To run the Django Development server go to manage.py directory.
And run the following command:
python manage.py runserver
And your Django Development server is running at http://127.0.0.1:8000/

Activated virtual environment using incorrect Python executable

I am working on a project through PyCharm. When I started the project, the project interpreter was a newly created virtualenv located in my project folder at /path/to/project_folder/venv and using base interpreter /usr/bin/python3.6.
When working in PyCharm, the Python Console seems to be using the right venv/Python executable etc. Running os.system("which python") returns /usr/bin/python.
Next, I activate this venv through my terminal (on Ubuntu 18.04) using the command source /path/to/project_folder/venv/bin/activate which works fine and shows me that it is activated with a (venv). However, if I run which python, it returns /home/user/anaconda3/bin/python.
Why is this occurring? How can I access the same Python interpreter from the PyCharm console through my Ubuntu terminal?
Same happened to me in a specific project.
Symptoms:
No executable taken from the venv; i.e:
which python3 from bash is not taken from venv
Python packages are not working from venv
Cause:
You renamed your project folder
Virtual environment PATH keeps old path to venv
It fails silently
Solutions:
Create a new venv and reinstall requirements, OR
Rename folder to its old name
Change PATH is not the solution. venv script creates some other routes in various files.
Note: Tested with python3 -m venv venv

Categories

Resources