I'm new to Windows and using the command line. I'm having issues with how the path works.
I installed Python 3 using Anaconda on a Windows 10, and I'm using a virtual environment that doesn't seem to recognize python.
$ python --version
bash: python: command not found
In the command line, Python is installed, but many packages like Flask and Pandas also aren't being recognized. I've used pip install, which works correctly
$ pip install flask
Requirement already satisfied: flask in c:\users\dta\anaconda3\lib\site-packages (1.0.2)
Requirement already satisfied: click>=5.1 in c:\users\dta\anaconda3\lib\site-packages (from flask) (6.7)
Requirement already satisfied: itsdangerous>=0.24 in c:\users\dta\anaconda3\lib\site-packages (from flask) (0.24)
Requirement already satisfied: Werkzeug>=0.14 in c:\users\dta\anaconda3\lib\site-packages (from flask) (0.14.1)
Requirement already satisfied: Jinja2>=2.10 in c:\users\dta\anaconda3\lib\site-packages (from flask) (2.10)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\dta\anaconda3\lib\site-packages (from Jinja2>=2.10->flask) (1.0)
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
But then running a program with either of those packages doesn't work and I get a result like this one:
Traceback (most recent call last):
File "app.py", line 1, in <module>
import flask
ModuleNotFoundError: No module named 'flask'
It seems like the path is set, but there's some issue with the command line recognizing it correctly. I've uninstalled and then reinstalled Python and made sure to check the box ‘Add Python to PATH’ during the installation but nothing has worked. Any ideas on how to fix this?
You most likely do not have Anaconda on your Path. Try:
echo %PATH%
if [Mini|Ana]conda is not there, open Anaconda CMD. Start typing on wundows Start Menu. In that, conda command should work. Type where conda. It show where conda is: then do something like
SETX PATH “%PATH%;%USERPROFILE%\Anaconda3\Scripts;%USERPROFILE%\Anaconda3”
This will set anaconda to Path. Close and Restart CMD
If you have different environments, try
conda env list
To activate your environment:
conda activate environmentName
Remember to use conda install ... over pip as it deals with upgrades and downgrade for compatibility issues.
if Anaconda is there, then you must have another Python their too that comes before Anaconda. That will be selected over Anaconda, unless you rearrange that Anaconda comes first before it.
If you do not want that, you can simply create an environment:
conda create -n awesome python=3.7
Then activate it and install your packages there:
conda activate awesome
conda install flask
python -V # Python 3.7
To see where Python looks for packages do:
python -c "import sys;print(sys.path)"
See where it is looking for packages.
Related
I am trying to learn FLASK. I am just following this tutorial. I have already created a venv for kivy, and all went right. But now I am learning flask and in CMD, when I pass:
pip install virtualenv
it outputs:
Requirement already satisfied: virtualenv in c:\users\new\appdata\local\programs\python\python39-32\lib\site-packages (20.3.0)
Requirement already satisfied: appdirs<2,>=1.4.3 in c:\users\new\appdata\roaming\python\python39\site-packages (from virtualenv) (1.4.4)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\new\appdata\roaming\python\python39\site-packages (from virtualenv) (1.15.0)
Requirement already satisfied: filelock<4,>=3.0.0 in c:\users\new\appdata\roaming\python\python39\site-packages (from virtualenv) (3.0.12)
Requirement already satisfied: distlib<1,>=0.3.1 in c:\users\new\appdata\roaming\python\python39\site-packages (from virtualenv) (0.3.1)
Then I used:
mkdir newproj
cd newproj
At last:
virtualenv venv
And it said:
Fatal error in launcher: Unable to create process using '"c:\program files\python39-32\python.exe"
"C:\Program Files\Python39-32\Scripts\virtualenv.exe" ': The system cannot find the file specified.
I tried adding "C:\Program Files\Python39-32\Scripts\virtualenv.exe" to path. But it did not work. How do I fix this?
as of python 3.3, python is shipped with its built-in virtual environment module venv, it's the official, the standard, the recommended and the difacto module.
refer to : https://docs.python.org/3/library/venv.html#module-venv
so you don't even need to install any 3rd module like virtualenv, pipenv .. to create and manage your virtual environments.
create the root folder for your project
C:\> mkdir newproj
C:\> cd newproj
create the virtual environment, (as good practice and as seen in many well-known projects on github .. named it venv)
C:\newproj> py -m venv venv
activate it
C:\newproj> venv\Scripts\activate
(venv) C:\newproj> pip list
(venv) C:\newproj> pip install flask flask-login ..
to deactivate it
(venv) C:\newproj> deactivate
C:\newproj>
Try to use :
python3 -m virtualenv venv
I'm having a problem when installing packages on my virtualenv.It all started when I upgraded my pip to the latest version. I tried to revert my pip version to where I find it stable. When I try to install, for example, django-tables2, it says:
Requirement already satisfied: django-tables2 in /usr/lib/python3.6/site-packages (2.3.1)
Requirement already satisfied: Django>=1.11 in /usr/local/lib/python3.6/dist-packages (from django-tables2) (2.2.4)
Requirement already satisfied: pytz in /usr/local/lib/python3.6/dist-packages (from Django>=1.11->django-tables2) (2019.2)
Requirement already satisfied: sqlparse in /usr/local/lib/python3.6/dist-packages (from Django>=1.11->django-tables2) (0.3.0)
WARNING: You are using pip version 19.3.1; however, version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
But when I check my folder in my virtualenv, it doesn't show there. I tried some commands like which pip and which pip3 and it says this:
(unidaenv) root#UnidaWebApplication:/home/unidaweb/unidaproject# which pip
/home/unidaweb/unidaproject/unidaenv/bin/pip
(unidaenv) root#UnidaWebApplication:/home/unidaweb/unidaproject# which pip3
/home/unidaweb/unidaproject/unidaenv/bin/pip3
(unidaenv) root#UnidaWebApplication:/home/unidaweb/unidaproject#
I also tried pip list but I can't find the package that I installed to my virtualenv.
I'm getting a bad gateway error when I try to add it on my settings.py, I don't really know how to fix this but when I'm in the version of pip that I know was stable running my project, I don't get this error and I can install any package that I needed to my project. Any help would be much appreciated. I'm stuck on this for about a week, hoping that someone could help me with this issue.
virtualenvs can break occasionally especially if the somebody updated the python executable the virtualenv was based or some packages / shared libraries of it.
I'd suggest to try out with a new virtualenv. (delete the broken one and replace it)
Further.
for debugging I suggest to type following two commands:
type -a python and type -a pip
In case your search path has some hidden surprises it could be safer to call
python -m pip instead of python though in a properly setup virtualenv it shouldn't make a difference.
I've searched but seems like most posts cannot find modules, once they are in the environment. My problem however is quite strange. I am getting a ModuleNotFound error when initialising my env.
daudnadeem$ virtualenv py-tpot
ModuleNotFoundError: No module named 'google'
Even though it shouldn't matter, google is installed.
daudnadeem$ pip install google
Requirement already satisfied: google in /usr/local/lib/python3.7/site-packages (2.0.3)
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.7/site-packages (from google) (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in /usr/local/lib/python3.7/site-packages (from beautifulsoup4->google) (2.0)
I tried uninstalling virtualenv, and reinstalling. That didn't work.
I managed to set up a vitualenv with python3 using: python3 venv myenv However I need a venv with python2.7 and python venv myenv does not work.
Anybody have any ideas?
Have you tried virtualenv -p python venvname . Where python points to python 2 version.
Install virtualenv if not present and try the above command.
Python Version 2.7
On windows 10 64bits
pip install <whatever>
command not working.
C:\new_software\Python27\Scripts>python -m ensurepip
Requirement already satisfied: setuptools in c:\new_software\python27\lib\site-packages\setuptools-28.8.0-py2.7.egg
Requirement already satisfied: pip in c:\new_software\python27\lib\site-packages\pip-9.0.1-py2.7.egg
C:\new_software\Python27\Scripts>python -m ensurepip --upgrade
Requirement already up-to-date: setuptools in c:\new_software\python27\lib\site-packages\setuptools-28.8.0-py2.7.egg
Requirement already up-to-date: pip in c:\new_software\python27\lib\site-packages\pip-9.0.1-py2.7.egg
C:\new_software\Python27\Scripts>pip install wheel
failed to create process.
C:\new_software\Python27\Scripts>python -m install pip install pip
C:\new_software\Python27\python.exe: No module named install
I have python 3.x and 2.7; in 3.x pip works fine; only in 2.7 it aint.
Based on reading articles online: I have completed:
1.environment variable set up.
2.python VC++ installed
Thank you all for your response. I read the link shared by #cricket_007.
Solution:
Update all .py files [firstline] inside /Scripts folder with current path of Python Home. You will notice it will be pointing to an older location.
Then try running pip command from new CMD prompt, should work fine.
I have recently just started the foray into running cygwin on windows.
Attempting to setup a development environment, and noticing some oddities.
so for example, I have installed virtualenvwrapper but when i open a new cygwin terminal i get (after setting appropriate lines in my .bashrc)
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
so i attempt to reinstall virtualenvwrapper using pip and i get
$ pip install virtualenvwrapper
Requirement already satisfied (use --upgrade to upgrade): virtualenvwrapper in c:\python27\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): virtualenv in c:\python27\lib\site-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): virtualenv-clone in c:\python27\lib\site-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): stevedore in c:\python27\lib\site-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): argparse in c:\python27\lib\site-packages (from stevedore->virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): six>=1.9.0 in c:\python27\lib\site-packages (from stevedore->virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): pbr!=0.7,<1.0,>=0.6 in c:\python27\lib\site-packages (from stevedore->virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): pip in c:\python27\lib\site-packages (from pbr!=0.7,<1.0,>=0.6->stevedore->virtualenvwrapper)
What gives? why is it installing it to the windows directory? sure enough i can see virtualenvwrapper is not installed in c:/cygwin64/lib/Python2.7/site-packages/
in fact that directory is completely bare.
I expected to see the updated version of pip i installed. it's of course in the windows directory.
I had previously installed virtualenvwrapper via pip on windows, but my understanding is that the windows environment and the cygwin terminal are totally seperate and shouldn't know about each other(?)
as you might expect this is also wrecking havoc with other packages.
for example attempting to install uwsgi i get this error:
Collecting uWSGI==2.0.7 (from -r _pip/requirements.txt (line 52))
Downloading uwsgi-2.0.7.tar.gz (772kB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "c:\cygwin64\tmp\pip-build-n5cvur\uWSGI\setup.py", line 3, in <module>
import uwsgiconfig as uc
File "uwsgiconfig.py", line 8, in <module>
uwsgi_os = os.uname()[0]
AttributeError: 'module' object has no attribute 'uname'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\cygwin64\tmp\pip-build-n5cvur\uWSGI
which i understand is because os.uname doesn't exist on windows. Why is the pip installer running setup using windows python?
------- update -------
I think i found the root cause
$ which pip
/c/Python27/Scripts/pip
so my questions are:
why is pip the windows one by default? or how did this happen?
-------- Update 2 ----------
i just discovered that the default PATH env variable in cygwin appends the windows one. sure enough the path to the windows pip is there.
$ echo $PATH
Is this expected? if so, why is this desireable? doesn't it increase the chance of unintentional conflicts like this one?
So I'll just leave this here as a warning to n00bs like myself.
cygwin appends the windows path to the cygwin terminal PATH env variable.
if you already have pip installed on windows and it is on your path it will work but with unexpected results like above.
to check make sure you do
which python
which pip
to confirm what version you are running.
only python 2.7.9 and up include pip by default and the package included in cygwin isn't there yet. so you will most likely need to install pip manually
if you had a cygwin terminal open, you will need to close all windows otherwise it remembers the path to the windows pip.
See this answer to setup easy_install in cygwin's python install.
https://serverfault.com/questions/7282/how-to-run-easy-install-in-cygwin
Once that is done, you can use easy_install to get pip.