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.
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.
A python newbie question:
On an Ubuntu system, I installed a python package using sudo pip install. (The package is called hlmm)
I'm using the miniconda3 environment and the only environment variable specified in my .bashrc is:
export PATH="/home/<my_username>/miniconda3/bin:$PATH"
Now I want to run a test script from the package I installed, which is located under a tests folder relative to where that package was installed.
I used pip list | xargs -exec pip show to look for the location of that package but it doesn't show up.
I also tried in python to import the package, using:
import hlmm
And I'm getting:
>>> import hlmm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'hlmm'
If I redo sudo pip install hlmm I get:
Requirement already satisfied: hlmm in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages (from hlmm)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from hlmm)
Requirement already satisfied: pysnptools in /usr/local/lib/python2.7/dist-packages (from hlmm)
Requirement already satisfied: pandas>=0.19.0 in /usr/local/lib/python2.7/dist-packages (from pysnptools->hlmm)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages (from pandas>=0.19.0->pysnptools->hlmm)
Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python2.7/dist-packages (from pandas>=0.19.0->pysnptools->hlmm)
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil>=2.5.0->pandas>=0.19.0->pysnptools->hlmm)
And, I do see the hlmm folder under /usr/local/lib/python2.7/dist-packages, but cannot find that tests folder:
ls -1 /usr/local/lib/python2.7/dist-packages/hlmm
__init__.py
__init__.pyc
hetlm.py
hetlm.pyc
hetlmm.py
hetlmm.pyc
How do I find its location? And, is the package really successfully installed despite the import hlmm error?
This was getting too long to be a comment, so I'm posting it as an answer.
Yeah, it sounds like pip installed it from your python 2.7 version. You should read this post: How to install PyPi packages using anacaonda conda command and this article: https://www.anaconda.com/using-pip-in-a-conda-environment/ to decide how you want to proceed. I generally use conda when possible, and pip if conda doesn't have a build. You might want to run pip uninstall hlmm then activate your conda env and use pip3 install hlmm. But, I think you should decide the best way to manage your environments after doing research.
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.
I noticed a strange phenomenon related to dist-packages paths. The order of my paths in my system-wide installation of python 3 (simply running python3 and then printing sys.path) is as follows:
/usr/local/lib/python3.4/dist-packages
/usr/lib/python3/dist-packages
i.e. the path in local is preferred. However, creating a virtual environment and running python3 after activating the environment gives:
/usr/lib/python3/dist-packages
/usr/local/lib/python3.4/dist-packages
The order is clearly reversed. Yet, pip still searches local first, which results in a different version of a library seen by pip dependencies and a different one used when importing.
Can someone explain the discrepancy?
EDIT:
When the virtualenv is activated, the pip used is the one installed in the virtualenv:
pip 9.0.1 from ~/.virtualenv/python3/lib/python3.4/site-packages (python 3.4)
and yet, despite the path pointing first to dist-utils in /usr/lib, it does resolve dependencies with what's in /usr/local/lib:
pip3 install --upgrade setuptools
Requirement already up-to-date: setuptools in ./.virtualenv/python3/lib/python3.4/site-packages
Requirement already up-to-date: appdirs>=1.4.0 in ./.virtualenv/python3/lib/python3.4/site-packages (from setuptools)
Requirement already up-to-date: packaging>=16.8 in /usr/local/lib/python3.4/dist-packages (from setuptools)
Requirement already up-to-date: six>=1.6.0 in ./.virtualenv/python3/lib/python3.4/site-packages (from setuptools)
Requirement already up-to-date: pyparsing in /usr/local/lib/python3.4/dist-packages (from packaging>=16.8->setuptools)