problems comes while creating virtualenv - python

I have installed python 3.10.2, while creating virtualenv
I did pip install virtualenv. then I create myenv (virtualenv mypython), but I got error like this. could you please help me what do I do
the error is :
C:\Users\ARROWIN PHOTOGRAPHY\Felix\djangoProject>virtualenv mypython
'virtualenv' is not recognized as an internal or external command,
operable program or batch file.

In python3 is better to use venv instead. Here are the steps to create your environment:
In your project directory, open the terminal:
python3 -m venv venv
Then:
source venv/bin/activate

Make sure that you have set up the python PATH variables correctly and that in your path e.g. ..\AppData\Local\Programs\Python\Python39\Scripts you can locate the python executable virtualenv.exe
If you are using multiple python versions on your local machine be careful while using PIP install. It is better to use the command pip3.x install ... (x is meant to be a specific version of pip e.g. pip3.9) so you can be sure you installed the virtualenv in the correct version of Python, and afterward, you can also select a specific python version when using virtualenv by virtualenv env -p pythonxx the xx is meant as a python version.

Related

"No Python at..." error after installing different version and changing the path variable

I use Windows 10. I was trying to pip install Vectorbt but the installation could not have been finished because there was an error when numba and llvmlite were suppose to be installed. I was using Python 3.10 and read that there is a compatibility problem with it. So I uninstalled it and installed Python 3.8.7. Afterwards I made sure that the system variable is set on the proper Python path. I closed everything and even restarted the system but in the command line or the powershell terminal in VSC I get the error "No Python at" and the directory of the previous 3.10 installation.
The variable is set corectly (was set as an admin).
Any ideas?
Maybe something with the registry?
Thanks!
I can recommend you use virtual environments to manage python versions (you'll never look back), high level steps:
cd mydir
virtualenv .venv # creates a virtual env dev (or python3 -m venv .venv)
source .venv/bin/activate # activates the virtual env
pip install -r requirements.txt # installs the required dependencies
python -m pytest # runs the unit tests
More details in the docs: https://docs.python.org/3/library/venv.html

How to create virtualenv with specific downloaded python version

I know there are some similar questions,but it is really hard for me to finish it.
I'm trying to create a virtualenv with python 3.7.7 in windows.
I have a downloaded python 3.7.7
C:\Users\willi\AppData\Local\Programs\Python\python-3.7.8-embed-amd64
Since I can built a virtualenv using:
python3 -m venv myenv
So I tried to modify it ,so that it can match specific python version:
python3 -m C:\Users\willi\AppData\Local\Programs\Python\python-3.7.8-embed-amd64\python.exe myenv
But it failed:
ModuleNotFoundError: No module named 'C:\\Users\\willi\\AppData\\Local\\Programs\\Python\\python-3')
Any friends can teach me how to build a virtualenv with python 3.7.7?
I think you haven't installed virtual environment in your local python
pip install virtualenv
and follow your steps. Stil, find the error. Try doing below methods, I think you will get your answer-
in command prompt
pip install virtualenv
go to the location, where you want to create your environment
cd location
virtualenv project_env_name
Now, you will find a python env in the desired location, Then go to scripts
cd project_env_name/scripts
activate
You will enter the environment you created. while leaving the environment, do
deactivate
To leave the environment.
This method works if you want to create the same python version environment as python version in your machine.
If you want to create an environment of the different version, you need to install the python of that version.

virtualenv: command not found in Python

I am trying to create a new virtual environment for a tutorial. I have installed virtualenv and virtualenvwrapper multiple times but every time I try creating a new virtual environment my terminal displays - mkvirtualenv: command not found. When I try finding out the version of virtualenv it shows virtualenv: command not found. Something similar was happening with my pip installation as well but then it got resolved when I used some command.
I would like to point out that my PATH seems to be really messed up. The PATH is pointing to /Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin. Please help.
I saw something else when I use pip show virtualenv it gives me details of the version and the author but when I use virtualenv --version it sends a virtualenv: command not found.
First of all, you will need to install virtualenv as it is a python 2 external dependency.
pip install virtualenv
this will allow you to use virtualenv globally.
Alternatively, you can use from Python 3.5+
python -m virtualenv venv
However if you dont wish to support python 2 you can use venv which is installed on from python 3.3
python3 -v venv venv
Took quite some time to figure it out but what worked for me was to install it using pip3 install instead of pip install
pip3 install virtualenv

Virtualenv installing a package in the global directory

I made sure to read this question and similar ones, but I couldn't find an answer to my problems.
My problem is: when I head into muy virtual env and activate it, if I install a package there, it is also installed elsewhere in my computer.
So, for example, if I type in the terminal:
cd home/Documents/Python/tests/my_virtual_env
source bin/activate
That activates the virtual environment. If I type:
pip3 install wget #just an example package
I see the installation process and I can run a .py script that uses wget. However, why is this package also installed elsewhere in my computer?
I made sure I hadn't that package installed beforehand using pip3 list.
I confirmed that package was installed elsewhere by running a .py script from other directories (using cd /etc.etc/ to change directory and then running it from there).
I deactivated the environment in the right moment.
I also realized that if I uninstall that package within the virtualenv, it is also uninstalled elsewhere.
Thank you so much for your help.
It could be that the pip3 command being executed is not actually tied to the virtual environment. So instead you could the following, which would work whether or not the virtual environment is activated:
$ path/to/my_virtual_env/bin/python3 -m pip install SomeProject
The following command should give you a relatively clear indication of where exactly the project has been installed, make sure it is in the site-packages directory of the virtual environment:
$ path/to/my_virtual_env/bin/python3 -m pip show SomeProject
So it should show something of the sort:
Name: SomeProject
...
Location: .../path/to/my_virtual_env/lib.python3.X/site-packages
However, why is this package also installed elsewhere in my computer?
The following shows where a binary is located:
$ which somecommand
It should be relatively easy to recognize if somecommand is in a Python virtual environment or not.

How do I install a python module in a virtual environment?

I am a beginner and read somewhere that we should always create virtual environments when working with Python. Therefore, I created a virtual environment using:
python -m virtualenv headlines
It copies all files with messages like
Using base prefix 'C:\\Program Files\\Python 3.5'
New python executable in C:\Users\Babu\headlines\Scripts\python.exe
Installing setuptools, pip, wheel...
Now, I want to install a module locally in this virtual environment using the following command:
python -m pip install feedparser
I think it is being installed in the Program Files Directory in Python 3.5 folder because the console shows:
copying build\lib\feedparser.py -> c:\program files\python 3.5\Lib\site-packages
error: could not create 'c:\program files\python 3.5\Lib\site-packages\feedparser.py': Permission denied
How can I resolve that?
I assume that you have already virtual environment folder successfully created.
First of all, you should be "inside" in your virtualenv in order to use it, thus for linux environments:
~$ source ${your_venv_folder_name}/bin/activate
will cause command line look like this
(venv)~$
Or for windows environments, like this:
python -m venv ${your_venv_folder_name}
According to this manual
python 3.4
If Python 3.4 is installed it is not necessary to install virtualenv
separately. Instead it is possible to use the venv module:
python < 3.4
virtualenv can be installed using the previously installed pip:
pip.exe install virtualenv
Now I see that you haven't enough permissions to install additional modules, so try to restart cmd terminal with administrator privileges according to this manual
Now then, with venv activated in current console and have sufficient privileges, it's should be easy to install modules from pip as usual.

Categories