virtualenv doesn't work correctly on windows - python

I am trying to use venv for my project and it doesn't work correctly.
So first of all I am activating my venv and than use command "pip freeze" to check if there are no modules installed from my computer. And there is an output^
user#DESKTOP-JMJSO6O C:\Users\user\Desktop\app\Scripts
$ activate
(app) user#DESKTOP-JMJSO6O C:\Users\user\Desktop\app\Scripts
$ pip freeze
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
accessify==0.3.1
appdirs==1.4.3
attrs==19.3.0
backcall==0.1.0
beautifulsoup4==4.8.2
bleach==3.1.0
bs4==0.0.1
...
And that is incorrect because I have no modules installed in this venv. What could be the problem?
UPD:
Trying pip --version with venv:
(app) user#DESKTOP-JMJSO6O C:\Users\user\Desktop\app\Scripts $ pip --version
WARNING: pip is being invoked by an old script wrapper. This will fail in a future
version of pip. Please see github.com/pypa/pip/issues/5599 for advice on fixing the
underlying issue. To avoid this problem you can invoke Python with '-m pip' instead
of running pip directly. pip 20.0.2 from
C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip (python 3.8)
Also I have founded another problem. For example, I have two python files in one directory:
- app/
- main.py
- conf.py
And when I am trying to import conf as module in main.py, I got the error:
ModuleNotFoundError: No module named 'conf'
Maybe the problem is with Windows? Becuase on the laptop with Windows I don't have any problems like that.

It seems that this problem is caused by two versions of pip, or a fail update attempt.
I suggest that you try following these instructions.
Alternatively try running where pip and pip --version inside and out side the virtual-env and look for differences.
I hope you'll figure this out, the github thread suggests the problem still doesn't have an obvious solution.

Related

Why are python modules not found despite installing them in pip?

I've been trying to use VS Code's python debugger on Linux (mint), which uses debugpy and it keeps giving the error "No module named '_ctypes'". Installing libffi-dev didn't fix it as suggested elsewhere on SO and neither did reinstalling python and python3; so, I tried installing debugpy through pip:
pip install debugpy
Which installs with no issues. However, both python and python3 commands cannot find the module despite the fact that the module is installed (which I can see when I enter pip list)
python -m debugpy
/usr/bin/python: No module named debugpy
python3 -m debugpy
/usr/local/bin/python3: No module named debugpy
So after trying to reinstall pip multiple times, I tried installing through the pip module
python -m pip install debugpy
/usr/bin/python: No module named pip
python3 -m pip install debugpy
/usr/local/bin/python3: No module named pip
So it seems my pip module is also missing too. It may have something to do with my multiple installations of python3 as it seems that there is one in /bin and in /usr/local/bin and the local installation is the one that gets called with the python3 command according to which python3.
This leads to multiple questions:
Should the pip module be installed in python, and if so how do I install it again?
How can I get the pip command to actually install the modules into python?
How can I ensure that there is only one python3 installation in Linux (mint/ubuntu)?
Thank-you. If it helps answer the question, I do not seem to have a PYTHONPATH variable.
i had same issue but it can be fixed by two methods.
reinstall pip for the latest python version you use.
2.use the version default python version which came with your python install
On ubuntu you can try to do sudo apt install python-pip python3-pip. Also there a couple ways you can try what PIP's documentation recommends: Installation
You can try checking sudo update-alternatives --config python maybe you'll see several python installations there.
Also you can check pip contents to find out what python binary it uses:
$ which pip
/usr/local/bin/pip
$ cat /usr/local/bin/pip
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/usr/bin/python3
I tried installing it with pip and it has worked for me. The problem you might have is that it is not installed in the correct version of python (e.g it installs for python2 instead of python3 or it installs in python3.8 instead of python3.9).
What you can do to avoid this problem is to create a virtual environment, as is explained in this link: https://docs.python.org/3/tutorial/venv.html. If you do that, remember to change the interpreter path in VSCode. At the bottom left of the screen there should be the python version that you are using. If you click on it you see different interpreter versions that you can use. Select 'Enter interpreter path' and manually choose the directory where you have saved the new python virtual environment.
It's difficult to narrow down a solution for apparently you have done a mess... To start, do yourself a favor:
Don't touch your System's Python!
Again, it is difficult for me to understand what is the current state of your Python scene... just promise me you'll fix your System's Python 2/3 (i.e, guarantee pip 2/3 there, using your system's package manager (apt, yum, etc)).
Then, start using some virtual environment manager, nowadays we have Pipenv (https://pipenv.pypa.io/), which can be a bit cumbersome at first but -- trust me -- in ~1 hour you'll love it.
Conda (https://docs.conda.io/) is also a great env manager (or the classics (pyenv, venv, etc...)).
...Just pick one and leave your OS' Python alone. You'll see that your issues will not only get simpler to diagnose but you'll also be able to sleep in peace ;)

How do modules installation work in Python?

[On a mac]
I know I can get packages doing pip install etc.
But I'm not entirely sure how all this works.
Does it matter which folder my terminal is in when I write this command?
What happens if I write it in a specific folder?
Does it matter if I do pip/pip3?
I'm doing a project, which had a requirements file.
So I went to the folder the requirements txt was in and did pip install requirements, but there was a specific tensorflow version, which only works for python 3.7. So I did """python3.7 -m pip install requirements""" and it worked (i'm not sure why). Then I got jupyter with brew and ran a notebook which used one of the modules in the requirements file, but it says there is no such module.
I suspect packages are linked to specific versions of python and I need to be running that version of python with my notebook, but I'm really not sure how. Is there some better way to be setting up my environment than just blindley pip installing stuff in random folders?
I'm sorry if this is not a well formed question, I will fix it if you let me know how.
Yes, there is. Setup an virtual environment.
pip install virtualenv #installs the library
virtualenv mypython #creates the environment
source mypython/bin/activate #activates the environment
Now, install your requirements through pip.
Afterwards, when your work is finished.
Just type deactivate to come out of the virtual environment.
There may be a difference between pip and pip3, depending on what you have installed on your system. pip is likely the pip used for python2 while pip3 is used for python3.
The easiest way to tell is to simply execute python and see what version starts. python will run typically run the older version 2.x python and python3 is required to run python version 3.x. If you install into the python2 environment (using pip install or python -m pip install the libraries will be available to the python version that runs when you execute python. To install them into a python3 environment, use pip3 or python3 -m pip install.
Basically, pip is writing module components into a library path, where import <module> can find them. To do this for ALL users, use python3 or pip3 from the command line. To test it out, or use it on an individual basis, use a virtual environment as #Abhishek Verma said.

sphinx_rtd_theme is no longer a hard dependency since version 1.4.0

C:\Users\Administrator\Desktop\item\code_serv\documents\api>make html
Running Sphinx v1.6.2 loading pickled environment... failed:
Can't get attribute 'WarningStream' on <module 'sphinx.util.nodes' from 'c:\\users\\administrator\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\sphinx\\util\\nodes.py'>
Theme error:
sphinx_rtd_theme is no longer a hard dependency since version 1.4.0.
Please install it manually.(pip install sphinx_rtd_theme)
How do I solve this?
I found another issue, I had two installations of sphinx, one via pip and another one via brew. Deleting one (I chose to remove installation done via brew ) solved this issue.
brew remove sphinx-doc
If it still doesnt work, try uninstalling and reinstalling
pip3 uninstall sphinx sphinx_rtd_theme
pip3 install sphinx sphinx_rtd_theme
Your question does not indicate whether you searched the web for "how to install sphinx_rtd_theme" or read its documentation.
The error message provides a clue:
Please install it manually. (pip install sphinx_rtd_theme)
Or you could try following the directions in the manual.
On my Mac OS X installation, I encountered this problem, despite following the simple instructions to the letter.
Others have reported having the problems as well, on this Github issue: https://github.com/readthedocs/sphinx_rtd_theme/issues/618
In my case, the problem turned out to be an issue with my python environment (I was using the default system python 2.7 for Mac). I ended up switching to pyenv with python 3.7.3, and that fixed the issue.
Instructions for Mac (from https://opensource.com/article/19/5/python-3-default-mac):
$ brew install pyenv
$ pyenv install 3.7.3
$ pyenv global 3.7.3
$ pyenv version
3.7.3 (set by /Users/mbbroberg/.pyenv/version)
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
To verify that it worked:
$ which python
/Users/mbbroberg/.pyenv/shims/python
$ python -V
Python 3.7.3
$ pip -V
pip 19.0.3 from /Users/mbbroberg/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pip (python 3.7)
Don't forget to pip install sphinx sphinx_rtd_theme afterward.
In my case (building from RTD theme source), the problem seemed to be caused by a change in behaviour of the html_theme_path config value in conf.py. Whilst paths relative to the makefile directory used to be accepted, paths must now be relative to the configuration directory:
html_theme_path
A list of paths that contain custom themes, either as subdirectories or as zip files. Relative paths are taken as relative to the configuration directory.
New in version 0.6.
— Sphinx documentation > Configuration
I had the same problem on a Windows 10 Pro laptop. I had installed Python 3.9 from the Windows store. I had to first find where Python and pip applications were installed and add that to the PATH variable. This was in a folder that was looked:
c:\users\<username>\appdata\local\programs\python\python39\Scripts
Then I installed sphinx using:
pip install -U sphinx
Then I had to set the SPHINXBUILD env variable to the right value:
SPHINXBUILD="c:\users\<username>\appdata\local\programs\python\python39\Scripts\sphinx-build.exe"
When I tried to use the sphinx_rtd_theme I kept getting the error:
Theme error:
sphinx_rtd_theme is no longer a hard dependency since version 1.4.0. Please install it
manually.(pip install sphinx_rtd_theme)
I ran the following command:
pip install sphinx_rtd_theme
But when I tried to run make html it gave the error:
Running Sphinx v3.5.1
Configuration error:
There is a syntax error in your configuration file: bad input (conf.py, line 57)
Finally I had to make the following changes in my conf.py file:
# Add this to the top of the conf.py file
import os
import sys
sys.path.insert(0, os.path.abspath('C:\\Users\\ <username>\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages'))
import sphinx_rtd_theme
extensions = [
"sphinx_rtd_theme",
]
It looks like sphinx-build is not able to get the location of the sphinx_rtd_theme package unless you give the explicit path in the manner above. “¯_(ツ)_/¯“

Why am I getting ImportError: No module named pip ' right after installing pip?

I have installed pip and ez setup. I also checked the system path and I can see the module in the folder structure. Still when i try to run pip command, I get an Import error saying no module named pip. I am running 32bit python on a windows7 machine
Just be sure that you have include python to windows PATH variable, then run python -m ensurepip
After running get_pip.py with python embed you have to modify your pythonXX._pth file. Add Lib\site-packages, to get something like this:
pythonXX.zip
.
Lib\site-packages
# Uncomment to run site.main() automatically
#import site
If you don't you will get this error:
ModuleNotFoundError: No module named 'pip'
or
python-3.8.2-embed-amd64\python.exe: No module named pip
λ pip
Traceback (most recent call last):
File "runpy.py", line 193, in _run_module_as_main
File "runpy.py", line 86, in _run_code
File "python-3.8.2-embed-amd64\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
λ python -m pip
python-3.8.2-embed-amd64\python.exe: No module named pip
This issue occurs with me while I was trying to upgrade pip version.
It was resolved with the following commands:
python -m ensurepip
The above command restores the pip and below mentioned upgrades it.
python -m pip install --upgrade pip
What solved the issue on my case was go to:
cd C:\Program Files\Python37\Scripts
And run below command:
easy_install.exe pip
Follow steps given in https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/. Replace x with version number of Python.
Open the pythonxx.__pth file, located in your python folder.
Edit the contents (e.g. D:\Pythonx.x.x to the following):
D:\Pythonx.x.x
D:\Pythonx.x.x\DLLs
D:\Pythonx.x.x\lib
D:\Pythonx.x.x\lib\plat-win
D:\Pythonx.x.x\lib\site-packages
try to type pip3 instead pip.
also for upgrading pip dont use pip3 in the command
python -m pip install -U pip
maybe it helps
turned out i had 2 versions of python on my laptop
both commands worked for me
python -m ensurepip
py -m ensurepip
both with another installation path
c:\tools\python\lib\site-packages
c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages
only the first path was in my %PATH% variable
First make sure that python is added in environment variable.
Try checking the version of pip or pip3. Use these commands to check.
For pip:
pip --version
For pip3:
pip3 --version
If you can see any version of pip and still not able to use it, then run the following command.
python -m ensurepip
This ensures the pip in your system.
Running these 2 commands helped me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
If you wrote
pip install --upgrade pip
and you got
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.2.1
Uninstalling pip-20.2.1:
ERROR: Could not install packages due to an EnvironmentError...
then you have uninstalled pip instead install pip.
This could be the reason of your problem.
The Gorodeckij Dimitrij's answer works for me.
python -m ensurepip
I found this post while looking for a solution for the same problem. I was using an embedded python distribution. In this case, the solution is to uncomment import site in the file python<version>._pth.
The ensurepip module was added in version 3.4 and then backported to 2.7.9.
So make sure your Python version is at least 2.7.9 if using Python 2, and at least 3.4 if using Python 3.
I'v solved this error by setting the correct path variables
C:\Users\name\AppData\Local\Programs\Python\Python37\Scripts
C:\Users\name\AppData\Local\Programs\Python\Python37\Lib\site-packages
I was facing same issue and resolved using following steps
1) Go to your paython package and rename "python37._pth" to python37._pth.save
2) curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
3) then run python get-pip.py
4) pip install django
Hope this help
I've solved this error downloading the executable file for python 3.7.
I've had downloaded the embeddeable version and got that error.
Now it works! :D
The method I'm going to tell might not be the correct way to do it. But this method solved my issue. I tried every solution on youtube and StackOverflow methods.
If you have two python versions installed. Delete one. I have the python 3.8.1 and 3.9.0 versions installed. I deleted version 3.9.0 from the C directory.
Now go to the control panel > System and security > System > Advanced system settings.
Click on 'environment variables'.
Select the path and click on 'edit'
Now, add the path of the python and also the path of pip module. In my case it was c:\python38 and c:\python38\scripts
This method solved my issue.
Instead of Python zip install python by python installer. It fixed the issue for me.

beginner installing nosetests package

I'm trying to install the following as per the learnpythonthehardway tutorial:
pip from http://pypi.python.org/pypi/pip
distribute from http://pypi.python.org/pypi/distribute
nose from http://pypi.python.org/pypi/nose/
virtualenv from http://pypi.python.org/pypi/virtualenv
I've visited these links and clicked the download button; each file is in my downloads folder now, and I unarchive/unzipped them- not sure what this means but it seemed required. Are they "installed"? If not, what does it mean to really install them? I've tried typing nosetests in the terminal (as the book says you should), as well as tried easy_install but that doesn't seem to work. It appears my understanding is limited in a number of ways here.
I get the following -bash: nosetests: command not found, but am trying to get:
nosetests . ---------------------------------------------------------------------- Ran 1 test in 0.007s
OK
This works on mac, it may work on linux
1)Open terminal (Be prepared to enter your password)
2)Type: sudo easy_install pip
3)Type: sudo pip install distribute
4)Type: sudo pip install nose
5)Type: sudo pip install virtualenv
Hope that helps, cheers!
They are not yet installed.
Each has its own vagaries about how exactly the install process works and in fact some of those packages will include the other packages with them. I.e.
"If you use virtualenv, a copy of pip will be automatically be
installed in each virtual environment you create."
http://pypi.python.org/pypi/pip
As a relatively new python user myself, (and having gone thru a similar process not long ago) I am eagerly awaiting the more complete answers that come back for this one.
Find out where the nosetests script is. On OSX:
/usr/local/share/nosetests
Execute directly, or set up a bash alias, perhaps in .bash_profile:
alias nosetests='/usr/local/share/python/nosetests'
alias nosetests3='/usr/local/share/python3/nosetests'
You were on the right track, but the package is actually called "nose". The documentation for nose (nosetests is the script) can be found here:
https://nose.readthedocs.org/en/latest/
The short answer is that you have 2 basic options: easy_install or pip. Install using setuptools/distribute: easy_install nose. Install using pip: pip install nose
Install Python 2.7 and after just do this (only on Windows - Windows PowerShell):
Setup PATH env:
C:\Python27\;C:\Python27\Scripts\", "User"
pip is already installed
3.
.\pip install distribute
4.
.\pip install nose
5.
.\pip install virtualenv

Categories

Resources