I'm not able create virtual environment using virtualenv - python

C:\Users\NAVEEN\Desktop\Demo>virtualenv venv
Traceback (most recent call last):
File "c:\users\naveen\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\naveen\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\NAVEEN\AppData\Local\Programs\Python\Python38\Scripts\virtualenv.exe\__main__.py", line 4, in <module>
File "c:\users\naveen\appdata\local\programs\python\python38\lib\site-packages\virtualenv\__init__.py", line 3, in <module>
from .run import cli_run
File "c:\users\naveen\appdata\local\programs\python\python38\lib\site-packages\virtualenv\run\__init__.py", line 12, in <module>
from .plugin.activators import ActivationSelector
File "c:\users\naveen\appdata\local\programs\python\python38\lib\site-packages\virtualenv\run\plugin\activators.py", line 6, in <module>
from .base import ComponentBuilder
File "c:\users\naveen\appdata\local\programs\python\python38\lib\site-packages\virtualenv\run\plugin\base.py", line 7, in <module>
from importlib.metadata import entry_points
ModuleNotFoundError: No module named 'importlib.metadata'

In Python 3.6+, the pyvenv module is deprecated.Your python interpreter version is 3.8.
Use the following one-liner instead:
python3 -m venv <myenvname>
Python already ships with its builtin "virtualenv" called venv since
version 3.3. You no longer need to install or download the virtualenv
scripts for Python 3.3+.
Refer the doc for more and Another stackOverflow Answer

You want to write it like this:
python -m venv {virtualenv}
replace '{virtualenv}' with the name you want your virtual environment to have.

Fisrt install virtualenv
Using comand
pip install virtualenv
Or
pip3 install virtualenv(for linux)
Then you can create a venv
You can check version ov virtualenv using comand
virtualenv --version

Related

problems installing a DVC lower version [0.9.4]

I need to install an older version of DVC, namely 0.9.4, in a Python virtual environment.
I used the command:
pip install dvc==0.9.4
Everything seemed to work fine. However, when I try to run a dvc pull command, I get the following error:
Traceback (most recent call last):
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\lbrandao\anaconda3\envs\my_env\Scripts\dvc.exe\__main__.py", line 4, in <module>
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\main.py", line 2, in <module>
from dvc.cli import parse_args
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\cli.py", line 8, in <module>
from dvc.command.init import CmdInit
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\command\init.py", line 1, in <module>
from dvc.project import Project
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\project.py", line 15, in <module>
from dvc.cloud.data_cloud import DataCloud
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\cloud\data_cloud.py", line 11, in <module>
from dvc.cloud.gcp import DataCloudGCP
File "c:\users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\cloud\gcp.py", line 4, in <module>
from google.cloud import storage as gc
ModuleNotFoundError: No module named 'google.cloud'
When I print the dvc version, I see:
0.9.4+6bb66e.mod
Can anyone please help? Thanks.
Assuming the remote storage is on Google Cloud based on that error, you may need to install the special dvc[gs] module instead, e.g.:
pip install dvc[gs]==0.9.4
See https://dvc.org/doc/install/linux#install-with-pip
BTW DVC 1.x should be backward compatible with DVC 0.9 in case you want to try a newer version.
Also, try to migrate your project to DVC 2.x (latest as of now), here are some guidelines: https://dvc.org/blog/dvc-2-0-release#breaking-changes
I was able to overcome the previous issue with:
pip install --upgrade google-cloud-storage

My pip is broken on Windows, how can I fix it?

Whenever I try to use pip, using any command I get this:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qzc5n2dfsdra8p0\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qzc5n2dfsd8p0\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\SE\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_q3.8_qzc5n2dfsd8p0\LocalCache\local-packages\Python38\site-packages\pip\__main__.py", line 23, in <module>
from pip._internal.cli.main import main as _main # isort:skip # noqa
File "C:\Users\SE\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qzc5n2dfsd8p0\LocalCache\local-packages\Python38\site-packages\pip\_internal\cli\main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\SE\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qzc5n2dfsd8p0\LocalCache\local-packages\Python38\site-packages\pip\_internal\cli\autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\SE\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qzc5n2dfsd8p0\LocalCache\local-packages\Python38\site-packages\pip\_internal\cli\main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "C:\Users\SE\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qzc5n2dfsd8p0\LocalCache\local-packages\Python38\site-packages\pip\_internal\cli\cmdoptions.py", line 24, in <module>
from pip._internal.cli.progress_bars import BAR_TYPES
File "C:\Users\SE\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qzc5n2dfsd8p0\LocalCache\local-packages\Python38\site-packages\pip\_internal\cli\progress_bars.py", line 8, in <module>
from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar
ModuleNotFoundError: No module named 'pip._vendor.progress'
PS C:\Users\SE> No module named 'pip._vendor.progress'No module named 'pip._vendor.progress'
I am on Windows 10, 64 bit, Python version 3.7.7.
I cannot use pip, how can I fix it?
If pip is broken after an attempted upgrade to a newer version, try the following:
Download get-pip.py and "Save As" the file using right-click.
Open a command prompt as an administrator
cd to the path where you saved the file, in my case
cd C:\Users\xyz\Downloads> then type python get-pip.py. It will install all required packages, such as wheel and pip.
To check if it installed correctly, type pip --version in the command line.
Hope my answer helps someone. Happy coding. 🙂
Try doing python -m pip install pytest. This should install it, and it will make it usable by your IDE.
Hope this helps!
You could follow the equivalent steps mentioned here and here (Both are closed issues on pip's github page) on your windows machine.
On windows you can do this:
python -m pip uninstall pip setuptools # Sometimes setuptools might be the problem
This will uninstall pip and setuptools.
After which you can reinstall them using
python -m ensurepip
This will install pip and setuptools.
I have tried this on my windows 10 machine running Python 3.7.4!

why does venv reference different python version

I followed djangogirls tutorial to get started with django and had everything working. Once I finished the basic tutorial, everything in working order, I decided to go through the steps again to make something new and become more familiar with using git, django, venv, etc.
fyi - I am on windows 10 and have python 2.7 and python 3.5 installed. I am using python 3.5.2 with django 1.10.4.
steps:
>mkdir v2
>cd v2
>"d:/python 3.5.2/python" -m venv myenv
>cd myenv/scripts/activate
(myenv) python -m pip install -U pip
for some reason this is the only way I was able to upgrade pip this time around
(myenv) d:/v2/myenv/scripts> pip install django~=1.10.0
(myenv) d:/v2/myenv/scripts> django-admin.py startproject mysite
This is where the magic doesn't happen:
d:\v2>django-admin.py startproject mysite2
Traceback (most recent call last):
File "D:\v3\myenv\Scripts\django-admin.py", line 2, in <module>
from django.core import management
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 10, in <module>
from django.apps import apps
File "C:\Python27\lib\site-packages\django\apps\__init__.py", line 1, in <module>
from .config import AppConfig
File "C:\Python27\lib\site-packages\django\apps\config.py", line 4, in <module>
from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
File "C:\Python27\lib\site-packages\django\core\exceptions.py", line 5, in <module>
from django.utils.encoding import force_text
File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 11, in <module>
from django.utils.six.moves.urllib.parse import quote, unquote
File "C:\Python27\lib\site-packages\django\utils\six.py", line 92, in __get__
result = self._resolve()
File "C:\Python27\lib\site-packages\django\utils\six.py", line 160, in _resolve
module = _import_module(self.mod)
File "C:\Python27\lib\site-packages\django\utils\six.py", line 82, in _import_module
__import__(name)
File "C:\Python27\lib\urllib.py", line 26, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: Module use of python35.dll conflicts with this version of Python.
As far as I am aware, I followed the same steps. I am not sure why the djano installed in my venv would be referencing python 2.7, since I thought if created my venv from the python 3.5.2 dir it would reference that version, along with anything I used pip for within that dir?
Can someone help me find what I am missing here? ty.
By default virtualenv uses python2. If you want to use python3, you have to specify it explicitly.
Run following command to setup virtualenv with python3:
virtualenv -p python3 envname
While in "Python 3.5.2/scripts" I ran:
virtualenv d:/<dirname>
Everything after(django-admin.py startproject projectname) worked correctly. Still not sure what went wrong here but maybe this helps someone else...

VIRTUALENVWRAPPER fails with zlib import error after EL CAPITAN update

After a recent El Capitan update, when I open the terminal I get the error below without attempting anything.
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/site-packages/virtualenvwrapper/hook_loader.py", line 8, in <module>
import inspect
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 39, in <module>
import tokenize
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tokenize.py", line 29, in <module>
from itertools import chain
ImportError: No module named itertools
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is
set properly.
If I run python (2.7.9) in the command line it works, but it fails when I try to import zlib with no module zlib error.
I tried to reinstall pip through easy install, so I can reinstall virtualenv and virtualenvwrapper, but when I try sudo easy install I get "zipimport.ZipImportError: can't decompress data; zlib not available".
So I then tried to change the .bash_profile, but I really don't know how to change it, because I don't understand path and environmental variables. CURRENT bash_profile content is:
export PATH=/usr/local/share/python:$PATH
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
My last hope is that if I can point the path in the right direction everything will get solved.

python3 in a virtualenv still uses library in /usr/lib/python2.7/dist-packages

I have successfully created a virtual environment with virtualenvwrapper using python3 at /usr/local/bin/python3 as default interpreter. My system python is python2.7
I can't use pip3 in this virtual environment because it keeps looking inside the default /usr/lib/python2.7/dist-packages
(python3.3.3)╭ ➜ xxx#xxx:~VIRTUAL_ENV/bin
╰ ➤ pip3.3
Traceback (most recent call last):
File "/home/xxx/virtualenv/python3.3.3/bin/pip3.3", line 7, in <module>
from pip import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
from pip.basecommand import command_dict, load_command, load_all_commands, command_names
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 11, in <module>
from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpFormatter
File "/usr/lib/python2.7/dist-packages/pip/baseparser.py", line 5, in <module>
import pkg_resources
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 45
def _bypass_ensure_directory(name, mode=0777):
^
SyntaxError: invalid token
Am I forgetting something?
I've also tried to install python3 into a custom directory inside /opt but that doesn't help.
Got it. My system $PYTHONPATH contains /usr/lib/python2.7/dist-packages so I simply removed it from the path and everything is now working properly.

Categories

Resources