Flask python framework installation - python

I have been trying to install and run it but it's not working.
I am suppose to create a virtual environment first in my working folder I was able to install virtualenv in python-scripts folder. I am using cmd line in Windows.
C:\Users\ADMIN\python\Scripts>pip install virtualenv
Requirement already satisfied: virtualenv in c:\users\admin\python\lib\site-packages (16.0.0)
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\ADMIN\python\Scripts>cd..
C:\Users\ADMIN\python>cd..
C:\Users\ADMIN>cd desktop
C:\Users\ADMIN\Desktop>cd flask_bookreview
C:\Users\ADMIN\Desktop\flask_bookreview>virtualenv flask
'virtualenv' is not recognized as an internal or external command,
operable program or batch file.

Read this link to install and activate your virtual enviroment:
http://pymote.readthedocs.io/en/latest/install/windows_virtualenv.html
when you successfully install and activate your virtual environment then run this command to install flask:-
pip install flask

try the answer of Manish Mahendru if you want to install it manually, but if you just want it too work, take a look at Anaconda (www.anaconda.com/download/).
It contains a ton of useful packages and every one I've used (till now) is already installed with it. flask is installed too.

For creating virtual environment you have to do,
python -m venv flaskenv
Now activate the virtualenv like
cd flaskenv
Scripts\activate.bat
Now install as
(flaskenv) C:/User/ADMIN/> pip install flask

Related

How to configure pip so that pip install is always called with argument --user?

I'm configuring a jupyterlab single-user instance. The users will need to install Python packages using
pip install <package-name>
I want to configure pip so that pip install is always called with argument --user, even if it is invoked without --user. Is it possible to achieve this? If so, how?
The reason behind it is that the $HOME directory is mounted on a persistent volume, and I want the user to still have its packages installed after restarting the jupyterlab server. By installing packages using pip install --user <package-name>, the packages will be stored in $HOME/.local/lib/python${PY_MAJOR}.${PY_MINOR}/site-packages and will therefore persist even after a server restart.
A solution that works on ubuntu:
Add this in $HOME/.pip/pip.conf:
[install]
user = yes
Documentation:
https://pip.pypa.io/en/stable/user_guide/#user-installs
https://pip.pypa.io/en/stable/topics/configuration/
https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-user
pip install <package-name>
#To run this code command prompt on python terminal to install a package
pip install --user
#python packages name on terminal to install with the help of
pycharm

Python virtual environment not installing packages in correct directory (python)

I have set up a virtual environment correctly have activated it and when I do "which python" it tells me the correct directory, but when I do pip install in the venv it installs the package in the default directory of the mac and not in my venv. I have tried using pycharm and installing packages with that, but it happens the same thing.
Edit:
Following I will do a walkthru of my steps, first I did python3 -m venv /path/to/new/virtual/environment, then I did source env/bin/activate, then I did which python and I got the intended directory, afterwards I did pip3 install numpy and I saw the installation process, then I did pip list and numpy was not there, I checked the directory manually and it still was not there. I retried all the same thing with pycharm with the same results.
Follow these steps in order -
In your current working directory :
python3 -m venv venv
source venv/bin/activate
(venv) pip3 install library_name
To check if libraries were properly installed or not :
(venv) pip3 freeze
and check if your installed libraries is displayed on the terminal screen or not.
To deactivate the virtual environment :
(venv) deactivate
This is due to permission issues
Run this command to change permission of your virtual environment folder
sudo chmod -R 777 venv
After activating your virtual environment
source venv/bin/activate
Then try to install Django by either Python3 or Python2
pip3 install django or pip install django
Then check the list of installed packages by either Python3 or Python2
pip3 list or pip list
NOTE: If you run sudo pip3 install django or pip install in virtual environment that is not writeable by default it will be installed outside of virtual environment
If you run pip3 install django or pip install in virtual environment that is not writtable by default it will be installed outside of virtual environment you will get OS Persmission Error
I have used pip3 and pip because you can install packages by either Python3 or Python2, thing to remember if you created virtual environment by Python3, use pip3 and if you created by using Python2 use pip.

python: how to install and use setuptools in virtual python

I do not have root previlege on a linux server so I want to creat a virtual python according to creating a "virtual" python.
After I run virtual-python.py, I do have python in ~/bin/python:
Then, according to setuptools PyPI page, I download ez_setup.py and run ~/bin/python ez_setup.py. Error occurs:
What should I do?
Looking at the linked website, it looks outdated. You use pip, not easy_install.
For installing development packages, I always take the following rules in account:
The system package manager is responsible for system-wide packages, so never use sudo pip. This doesn't just match the question, but this is always a good idea.
The package manager packages are probably outdated. You'll want an up-to-date version for development tools.
I recommend the following way to install local development tools.
$ # Install pip and setuptools on a user level
$ curl https://bootstrap.pypa.io/get-pip.py | python - --user
$ # Add the executables to your path. Add this to your `.bashrc` or `.profile` as well
$ export PATH=$PATH/$HOME/.local/bin
At this point pip should be accessible from the command line and usable without sudo. Use this to install virtualenv, the most widely used tools to set up virtual environments.
$ pip install virtualenv --user
Now simply use virtualenv to set up an environment to run your application in:
$ virtualenv myapp
Now activate the virtual environment and do whatever you would like to do with it. Note that after activating the virtual environment, pip refers to pip installed inside of the virtualenv, not the one installed on a user level.
$ source myapp/bin/activate
(myapp)$ pip install -r requirements.txt # This is just an example
You'll want to create a new virtual environment for each application you run on the server, so the dependencies can't conflict.

Can pip copy dependency source into my virtualenv?

I am a bloody beginner in Python and Django. To set up a environment on my Windows machine, I performed the following steps.
Install Python 3.4
Use pip to install virtualenv
Create a project folder and set up a virtualenv there
Download Django 1.7b1 release from the official site
Extract the archive in my downloads folder
Install it into my virtualenv
For the last step, I used pip from my virtualenv.
[project]\scripts\pip.exe install -e [downloads]\Django-1.7b1
From the global python interpreter I can't import django, as expected. When using the python executable from the virtualenv, it works. But the import only succeeds as long as I have the Django source in my downloads folder. Instead, I would like to include it into my virtualenv.
Can I make pip to automatically copy the Django source into my project folder?
Install django via pip inside the virtualenv. I'm running Linux but you should be able to run the commands on windows.
If you need a version that's not in PyPi, download the package and install it to the virtualenv site-packages-folder.
My site-packages folder for project is in ~/venvs/project/lib/python2.7/site-packages.
To install there:
pip install downloads/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages
Django will install to the site-packages folder and is now importable from within the virtualenv. Downloads/Django-1.7b1 is no longer needed.
Below is an example where I'm installing Django 1.7b1 from a local archive to the site-packages-folder of my virtualenv:
(project)msvalkon#Lunkwill:/tmp$ pip install /tmp/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages/
Unpacking ./Django-1.7b1.tar.gz
Running setup.py egg_info for package from file:///tmp/Django-1.7b1.tar.gz
-- SNIP --
Successfully installed Django
Cleaning up...
(project)msvalkon#Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.7b1
(project)msvalkon#Lunkwill:/tmp$ deactivate
# I've got a really old version installed globally, but you can see
# that the installation worked.
msvalkon#Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.5.1
After this you should find the following output when doing pip freeze while the virtualenv
is activated:
(project)msvalkon#Lunkwill:/tmp$ pip freeze
Django==1.7b1
argparse==1.2.1
wsgiref==0.1.2

pip freeze does not show all installed packages

I am using a virtualenv. I have fabric installed, with pip. But a pip freeze does not give any hint about that. The package is there, in my virtualenv, but pip is silent about it. Why could that be? Any way to debug this?
I just tried this myself:
create a virtualenv in to the "env" directory:
$virtualenv2.7 --distribute env
New python executable in env/bin/python
Installing distribute....done.
Installing pip................done.
next, activate the virtual environment:
$source env/bin/activate
the prompt changed. now install fabric:
(env)$pip install fabric
Downloading/unpacking fabric
Downloading Fabric-1.6.1.tar.gz (216Kb): 216Kb downloaded
Running setup.py egg_info for package fabric
...
Successfully installed fabric paramiko pycrypto
Cleaning up...
And pip freeze shows the correct result:
(env)$pip freeze
Fabric==1.6.1
distribute==0.6.27
paramiko==1.10.1
pycrypto==2.6
wsgiref==0.1.2
Maybe you forgot to activate the virtual environment? On a *nix console type which pip to find out.
You can try using the --all flag, like this:
pip freeze --all > requirements.txt
Although your problem was specifically due to a typo, to help other users:
pip freeze doesn't show the dependencies that pip depends on. If you want to obtain all packages you can use pip freeze --all or pip list.
If you have redirected all the pre-installed packages in a file named pip-requirements.txt then it is pretty simple to fix the above issue.
1) Delete your virtualenv folder or create new one (I am giving it a name as venv)
rm -rf venv && virtualenv venv
2) Install all the requirements/dependencies from the pip-requirements.txt
pip install -r pip-requirements.txt
3) Now you can check the installed packages for your Django application
pip freeze
4) If you had forgotten to update your requirements file(pip-requirements.txt), then install fabric again (Optional Step)
Note: After installing any dependency for your Django app, always update the requirements in any file as follows (make sure your virtualenv is activated)
pip freeze > pip requirements.txt
That's it.
Adding my fix in addition of above fix also ,
I was also facing the same issue on windows,even after activating the virtualenv too pip freeze was not giving me all list of installed packages. So i upgraded my pip with python -m pip install --upgrade pip command and then used pip freeze.
This time it worked and gave me all list of installed packages.
This might be stupid but I have got the same problem. I solved it by refreshing vs code file directory (inside vscode there is a reload button). :)
If none of the above answers are working for you.
As with me you might have problem in you venv and pip configuration.
Go inside your venv/bin and open pip and see the 2nd line as:
'''exec' "path/to/yourvenv/bin/python3" "$0" "$#"
See if this line is correctly pointing inside your venv or not
For example in my case.
I initially named my virtual environment as venv1
and later just renamed it to venv2.
In doing so my pip file 2nd line had: '''exec' "venv1/bin/python3" "$0" "$#"
which to work properly should have: '''exec' "venv2/bin/python3" "$0" "$#" notice "venv2" not "venv1" since venv1 in now renamed to venv2.
Due to this python was looking inside pip of venv2 and throwing error or not working as desired.
For those who added Python modules via PyCharm IDE, after generating a virtual environment from the command prompt, good luck! You will need to rebuild the requirements.txt file manually with the ones missing by first running pip3 freeze and adding what is missing from PyCharm.
I highly suggest switching to Visual Studio Code.

Categories

Resources