I am trying to create a virtual env for my flask project. However I tried using both pipenv and virtual env, but both method results in an error. I suspect that it is due to the path.
When I input pipenv shell, this is the log
Creating a virtualenv for this project…
Pipfile: C:\Users\Yk\Pipfile
Using C:\Users\Yk\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe (3.7.6) to create virtualenv…
[== ] Creating virtual environment...The path C:\Users\Yk\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe (from --python=C:\Users\Yk\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe) does not exist
Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pipenv\cli\command.py", line 390, in shell
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=state.pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pipenv\core.py", line 2156, in do_shell
[pipenv.exceptions.VirtualenvCreationException]: three=three, python=python, validate=False, pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pipenv\core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]:
Failed to create virtual environment.
A empty pipfile is created
When I try to use Virtual Env virtualenv env, this is the log:
Using base prefix 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0'
New python executable in C:\Users\Yk\DOCUME~1\Code\WEBDEV~1\Flask\TESTPR~1\env\Scripts\python.exe
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\virtualenv.exe\__main__.py", line 7, in <module>
File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 870, in main
symlink=options.symlink,
File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 1162, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "C:\Users\Yk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 1532, in install_python
shutil.copyfile(executable, py_executable)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 120, in
copyfile
with open(src, 'rb') as fsrc:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Yk\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe'
I have tried unistalling and reinstalling both modules.
I am using python 3.7.
How can i solve this error and use Pipenv? Thank you!
First, check your PATH for python execution or try with this command;
pipenv --rm
pipenv install
It might work, from your error code it will not detect python thats the problem
Okay so basically I reinstalled python. I suspected that it had to do with path, but i couldnt debug it after many hours.
Before i uninstalled though, it is important to remember the modules. So I did
pip freeze --local >pipfreeze.txt
After reinstalling,
pip install --upgrade --force-reinstall -r pipfreeze.txt at the same directory
Related
I am trying to create a new virtual environment using python on Windows 10.The command sets up the folders/subfolder but does not include the necessary scripts to activate the environment.(The folder is empty).
Stack Trace:
C:\Users\mcfry\Documents\Development\Django_Dev\django_test>python3 -m virtualenv my_env
Using base prefix 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0'
New python executable in C:\Users\mcfry\Documents\Development\Django_Dev\django_test\my_env\Scripts\python.exe
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\mcfry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 2632, in <module>
main()
File "C:\Users\mcfry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 870, in main
symlink=options.symlink,
File "C:\Users\mcfry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 1156, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "C:\Users\mcfry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 1526, in install_python
shutil.copyfile(executable, py_executable)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\mcfry\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe'
The command you are using is invalid.
Use the following command:
python3 -m venv myenv
or, if you are using virtualenv package, use the following:
virtualenv myenv
Find more details here : Python venv Python virtualenv
I am new in Python and to be coder :) I am trying to create and active virtualenv, searching for days to fix this problem but I couldn't, can you help me pls..
Thank you.
Let me show you my administrator:
Using base prefix 'c:\\users\\büşra\\appdata\\local\\programs\\python\\python37'
New python executable in C:\Users\Büşra\Desktop\Django-Virtualenv\myenv\Scripts\python.exe
Complete output from command C:\Users\Büşra\Deskt...v\Scripts\python.exe -m pip config list:
Could not import runpy module
ModuleNotFoundError: No module named 'runpy'
----------------------------------------
Traceback (most recent call last):
File "c:\users\büşra\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Büşra\AppData\Local\Programs\Python\Python37\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 793, in main
symlink=options.symlink,
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 1087, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 935, in install_wheel
_install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 964, in _install_wheel_with_search_dir
config = _pip_config(py_executable, python_path)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 1038, in _pip_config
remove_from_env=["PIP_VERBOSE", "PIP_QUIET"],
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 886, in call_subprocess
raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command C:\Users\Büşra\Deskt...v\Scripts\python.exe -m pip config list failed with error code 1```
On a windows machine you would activate the virtual environment as follows:
cd into the project directory, if your virtual environment is named venv then this
venv\scripts\activate will activate the virtual environment
I am using Influxdb python client to write data to Influxdb.
But, I am failing to import the influxdb module in my file.
It successfully gets imported in the shell, but does not work in the file.
Here is the
print '\n'.join( sys.path )
from my shell
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/pymodules/python2.7
and here is the same from my file,
/home/azureuser/pranav/book/vogo-backend-v2/book
/home/azureuser/.virtualenvs/book/lib/python2.7
/home/azureuser/.virtualenvs/book/lib/python2.7/plat-x86_64-linux-gnu
/home/azureuser/.virtualenvs/book/lib/python2.7/lib-tk
/home/azureuser/.virtualenvs/book/lib/python2.7/lib-old
/home/azureuser/.virtualenvs/book/lib/python2.7/lib-dynload
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/home/azureuser/.virtualenvs/book/local/lib/python2.7/site-packages
/home/azureuser/.virtualenvs/book/lib/python2.7/site-packages
/home/azureuser/pranav/book/vogo-backend-v2/book
Here is the
sys.executable #from file
/home/azureuser/.virtualenvs/book/bin/python
sys.executable #from the shell
/usr/bin/python
If I install it without using sudo pip , then it raises an exception,
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
pycompile=self.pycompile,
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
os.makedirs(destsubdir)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/distpackages/influxdb-4.0.0.dist-info'
Storing debug log for failure in /tmp/tmpokCmFo
Please explain why the problem is coming ? and also the solution.
First create the virtual environment properly:
virtualenv my_env
Activate the virtualenv:
source my_env/bin/activate
Inside your virtualenv install the client again using --no-cache-dir flag:
pip install influxdb --no-cache-dir
Try accessing the same in your .py files.
This will definitely fix your issue!
I am trying to pip install pandas on a mac. I have python 3.6 installed.
When I pip install in the terminal I get the following error:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pandas'
Could you possibly edit the error into a formatted code block by highlighting it and pushing ctrl+k so it is easier to read? Thanks.
Edit: Also, I just looked through and at the bottom it says permission denied. Try rerunning the command as an admin. I.E try this command:
sudo pip install pandas
You might have already noticed, Mac come with a built in Python, python 2.7. If you read your traceback: /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py it's pointing to the 2.7 dir. this dir is in the Library folder so you don't have permission to install to it.
But you state that you have Python 3.6 installed as well, so if you wanted to install to that indtead. Do pip3 install pandas or python3 -m pip install pandas this help specify the python version. And if you want to run python 3.6 in terminal, type python3 instead of just python
I am trying to install packages using PIP but it doesn't work for me initially it gives the permission denied error and after that when I tried to use easy_install it gives me this error :->
Searching for mezzanine
Reading https://pypi.python.org/simple/mezzanine/
Reading http://github.com/stephenmcd/mezzanine/
Reading http://mezzanine.jupo.org/
Best match: Mezzanine 3.1.8
Downloading https://pypi.python.org/packages/source/M/Mezzanine/Mezzanine-3.1.8.tar.gz#md5=dcc46016b866ea8de1c87fb9dffd9163
Processing Mezzanine-3.1.8.tar.gz
Writing /tmp/easy_install-2cSSS_/Mezzanine-3.1.8/setup.cfg
Running Mezzanine-3.1.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2cSSS_/Mezzanine-3.1.8/egg-dist-tmp-uDjreS
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 8, in ?
sys.exit(
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1924, in main
with_ei_usage(lambda:
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1911, in with_ei_usage
return f()
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1928, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "/usr/local/lib/python2.4/distutils/core.py", line 149, in setup
dist.run_commands()
File "/usr/local/lib/python2.4/distutils/dist.py", line 946, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 374, in run
self.easy_install(spec, not self.no_deps)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 609, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 639, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 825, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1031, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1016, in run_setup
run_setup(setup_script, args)
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 68, in run_setup
DirectorySandbox(setup_dir).run(
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 120, in run
return func()
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 71, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 22
with open(e, "r") as f:
^
SyntaxError: invalid syntax
After this when I again try to use pip then I am getting different error (not permission denied) :
File "/home/rishi/bin/pip", line 8, in ?
sys.exit(
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 357, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2394, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2108, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/rishi/lib/python2.4/pip-1.5.6-py2.4.egg/pip/__init__.py", line 9, in ?
from pip.log import logger
File "/home/rishi/lib/python2.4/pip-1.5.6-py2.4.egg/pip/log.py", line 19
real_consumer = (consumer if not isinstance(consumer, colorama.AnsiToWin32)
^
SyntaxError: invalid syntax
Now I don't know what I am doing wrong , can anybody help me ?
EDIT :- syntex errro solved due to wrong python version , I was using 2.4 .
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/mezzanine'
$which pip result is
~/bin/pip
Just add the --user option to your pip command, it will install with your logged in user permissions:
pip2.7 install mezzanine --user
as Daniel Roseman noted - the syntax error came from using Python2.4
the permission problem is caused by trying to install into system Python, what requires sudo or being root
Possible solutions
Install into system Pyhton (using sudo)
$ sudo pip install mezzanine
This will spoil the system Python and is not much recommended. It would be well acceptable if you are e.g. under Docker.
Install into user profile
$ pip install --user mezzanine
It will install the package into user scheme and will not spoil system Python.
This is more acceptable, but can soon become messy environment to run code in, as Python will import form user scheme, sometime from system.
Use virtualenv
Assuming you have virtualenv installed:
$ cd ~/projects
$ mkdir mezza
$ cd mezza
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install mezzanine
$ pip freeze
mezzanine==3.1.8
(there will be a bit more lines from freeze).
This installs into virtualenv, which is easy to recreate, destroy, and does not mess up with other environments.
With virtulanevwrapper you will get set of additional tools, which will simplify your environment a lot.