I initialize my project with virtualenv through these steps(in Windows 7 OS):
$ cd myproject
$ virtualenv venv
$ venv\scripts\activate
and then I try to install flask
$ pip install Flask
but I found the flask isn't install in my /venv/lib/site-packages folder
it is still install in my C:/Python27/lib/site-packages folder
Is this correct? I think it should be install in the venv folder
If this is incorrect, what should I do?
Try using the Scripts\pip.exe in your venv folder.
Start over with CMD. Recreate your virtualenv using only CMD. Then do a pip freeze. Things should work now. The reason why git-bash does not work is because it has only the PATH for git, and nothing else.
Related
On command $which python3$ , the location says /opt/homebrew/bin/python3 on my Mac. Is this okay for python to be in other directory than /usr/local/ ?
Yes. It will work. I mean if you change the location of installation directory, mac os will recognize it and python3 instruction will work.
Yeah it's absolutely ok. But it's better to create a project wise virtual env so that you don't messed up installing so many third party libraries globally in your system which could break system tools and other projects.
Installing vitualenv:
python3 -m pip install --user virtualenv
Creating a virtual environment.
cd {{your project directory}}
python3 -m venv env
Activate the virtualenv:
source env/bin/activate
Now if you run which python you will see the python is from your newly created virtual env.
When I try python3 -m venv venv, terminal returns
python3: posix_spawn: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.82.7:No such file or directory
I have seen other posts mentioning Home Brew related issues but I doubt this is the case. I did try uninstalling and installing Python.
Note: I was connected to localhost with a virtualenv. When I tried again later on, this was returned. I am building a Flask application.
Now you can use pipenv library for creating the virtual environment.
pipenv install pipenv
for example:
mkdir testapp
cd testapp
pipenv shell
Now the virtual environment is ready.
Then to install libraries in the virtual environment instead of "pip" you have to use "pipenv".
For example:
pipenv install requests
pipenv install flask
Then to write the requirements.txt you can use
pip freeze > requirements.txt
To uninstall libraries:
pipenv uninstall requests
Each time to work on the virtual environment:
pipenv shell
How to exit the virtual environment?
exit
I have been trying for two days on installing virtualenv on cmd prompt.
Does anyone have a solution to this problem?
I think you are using Windows.
To install virtualenv in windows, follow these steps:
Open scripts folder where pip is located in cmd
Type pip install virtualenv
Then you should install virtualenv wrapper for windows. Type this code pip install virtualenvwrapper-win
Create project dir: mkvirtualenv myproject
Set myproject dir as current dir: setprojectdir ..../myprojectdir
You are good to go. When you want to deactivate, simply type deactivate
Under C:\Python27\ArcGIS10.2\Scripts I have the following installed:
-easy install
-pip
-virtualenv
However, whenever i go to activate my virtualenv in the following directory C:\Users\username\djangotest i type in the command line the following code: C:\Python27\python -m venv myvenv and i get a not recognized as internal or external command response. I am following the setup steps on http://tutorial.djangogirls.org/en/django_installation/index.html
Am i setting virtual env in the wrong filepath?
Thanks
If my memory serve me right, only python3.3 support -m to create virtualenv. Version prior to that you have to use virtualenv to install virtual enviroment.
pip install virtualenv
virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>
Update:
C:
CD\
virtualenv -p C:\Python27\python.exe MyVirtualEnv
That should create a "MyVirtualEnv" virtualenv folder in your c: drive.
How do you install virtualenv correctly on windows?
I downloaded virtualenv1.9.1 from here and tried installing it with:
python virtualenv.py install
but it does not appear in MyPythonPath/Scripts
I tried the same way installing virutalenvwrapper-win and it installed correctly. But I can't use it because I don't have virtualenv
python.exe: can't open file
'MyPythonPath\Scripts\virtualenv-script.py': [Errno 2 ] No such file or
directory
The suggested way to install Python packages is to use pip
Please follow this documentation to install pip: https://pip.pypa.io/en/latest/installing/
Note: Python 2.7.9 and above, and Python 3.4 and above include pip already.
Then install virtualenv:
pip install virtualenv
Since I got the same error as mentioned in the question inspite of installing with:
pip install virtualenv
I would like to add a few points, that might also help someone else solve the error in a similar way as me. Don't know if that's the best way, but for me nothing else helped.
Install virtualenv
pip install virtualenv
Move into Scripts directory
cd C:\Python27\Scripts
Create a virtual env.
python virtualenv.exe my_env
Activate the virtual env.
my_env\Scripts\activate.bat
Deactivate the virtual env.
my_env\Scripts\deactivate.bat
install virtualenv
pip install virtualenv
create a virtual environment
python -m virtualenv demoEnv
Activate the environment
demoEnv\Scripts\activate
To deactivate
deactivate
There is an other way to install Python packages.
1: download the package, you want
2: open commander (press the win start-button and search for cmd)
3: cd into the folder where you downloaded your package
4: type: "python setup.py install"
For installing virtualenv, you'll have to either install it using pip as mentioned in the answer by woozyking or you'll have to do something like this:
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz
$ tar xvfz virtualenv-1.9.1.tar.gz
$ cd virtualenv-1.9.1
$ [sudo] python setup.py install
The command which you have used can be used to create a virtualenv. I would recommend you go through these small videos on virtualenv and virtualenvwrapper to get a better understanding:
python-power-tools-virtualenv
virtualenvwrapper
Creating a Virtual Environment on Windows
1. Create a virtual environment
python -m venv myenv
2. Activate
.\myenv\Scripts\activate
3. Extra information
To disable write
deactivate
These commands will also work on windows
myenv\Scripts\activate
myenv\Scripts\activate.bat
.\myenv\Scripts\activate.bat
Be careful with slashes:
myenv/Scripts/activate.bat
I prefer using this naming:
python -m venv .venv
.venv\Scripts\activate
4. Screenshot
5. Sources
https://code.visualstudio.com/docs/python/tutorial-django
https://code.visualstudio.com/docs/python/tutorial-flask