When trying to deploy a Kivy App using PyInstaller, I am getting Permission Denied errors even when using and Administrator CMD. The folder has all open editing options for every user. Python has firewall access. How to fix this?
PS C:\Users\theguy\Documents\Python\myapp-build> python -m PyInstaller --name "MyApp" "./"
422 INFO: PyInstaller: 3.3.1
422 INFO: Python: 3.6.5
424 INFO: Platform: Windows-10-10.0.17134-SP0
425 INFO: wrote C:\Users\theguy\Documents\Python\myapp-build\myapp.spec
426 INFO: UPX is not available.
427 INFO: Extending PYTHONPATH with paths
['C:\\Users\\theguy\\Documents\\Python',
'C:\\Users\\theguy\\Documents\\Python\\myapp-build']
428 INFO: checking Analysis
428 INFO: Building Analysis because out00-Analysis.toc is non existent
429 INFO: Initializing module dependency graph...
432 INFO: Initializing module graph hooks...
434 INFO: Analyzing base_library.zip ...
3859 INFO: running Analysis out00-Analysis.toc
3861 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Anaconda3\python.exe
4398 INFO: Caching module hooks...
4402 INFO: Analyzing C:\Users\btdav\Documents\Python\
Traceback (most recent call last):
File "C:\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 101, in <module>
run()
File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 94, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 213, in __init__
self.__postinit__()
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
self.assemble()
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 415, in assemble
priority_scripts.append(self.graph.run_script(script))
File "C:\Anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 201, in run_script
self._top_script_node = super(PyiModuleGraph, self).run_script(pathname)
File "C:\Anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1334, in run_script
with open(pathname, 'rb') as fp:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\theguy\\Documents\\Python\\myapp-build'
Trick is to make a new directory outside of the one you are building, and then make the build reference the main.py of the Kivy app like in the code below. This fixes permission errors, even from a regular CMD.
PS C:\Users\theguy\Documents\Python\myapp-build> python -m PyInstaller --name "MyApp" "C:\Users\theguy\Documents\Python\myapp\main.py"
I met the same problem!
I figure out it is my antivirus software(Bitdefender) thinks the write out .exe is dangerous, so it block the action.
After I add my work folder to antivirus software Exclusions then reboot computer, it works.
Update:
You need to "Code Signing" your .exe file to make antivirus software think it is less dangerous.
In Windows:
Using OpenSSL to create self-signing, then using Win10 SDK signtool.exe
OpenSSL Command Example:
openssl genpkey -out privkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:4096
openssl req -new -x509 -key privkey.pem -out cert.pem -days 3650
openssl pkcs12 -inkey privkey.pem -in cert.pem -export -out privkey_cert.pfx -passout pass:[PASSWORD]
signtool Command Example:
signtool sign /debug /f privkey_cert.pfx /p [PASSWORD] [EXECUTE_FILE.exe]
Update 2:
Avoid using command with .spec file
$ pyinstaller FILE.spec
Using Auto PY to EXE to instead of .spec
I don't know WHAT happen with .spec file, but it produces single executable file more problems than .py file do
Update 3:
Make sure every time to clear auto-py-to-exe "Building directory" before executing auto-py-to-exe, you may execute ones to get temp folder path.
for example:
Output
Running auto-py-to-exe v2.9.0
Building directory: C:\Users\John\AppData\Local\Temp\tmpevxvuugz
Provided command: pyinstaller --noconfirm --onefile --windowed ...
Update 4:
I reinstall entire windows os, then run the same thing without clear "Building directory" it turn out is fine! I rethink about it is a virus to infect "Building directory" make all this problem.
I had this problem when my current directory was set to C:\Users\[User]\Desktop\[Some-Folder].
I solved it by changing my current directory to G:\[Some-Other-Folder].
Presumably, this worked because the latter directory didn't require as many permissions.
TL;DR try changing your current directory to one that you know requires no special permissions.
I'm giving this answer in case anyone encounters my scenario. I spent a good deal of time trying other proposed solutions presented here. However, none resolved my file permission errors. Also, while my solution below works for me, I still don't understand why I'm getting a permission error in the first place.
Note that I use pyenv to manage several distributions, though I don't think that is relevant to the issue. Additionally, Pyinstaller failed in the same way with several different python versions I used it on.
Also, note that I know my answer to modify the package source is the "wrong way to do it", but it worked for my edge case and allowed me to continue forward.
When trying to build a single file executable, I kept getting the PermissionError: [Errno 13] Permission denied issue when PyInstaller attempted to access the created .exe to add the final payload data. As mentioned, I tried all the permission/admin/disable-defender tricks I found in other answers here, but the majority of the time, the build process kept failing with a file permissions error. I did notice, however, that sometimes, every once in a rare while, PyInstaller would build the executable correctly, maybe once out of every twenty times, which I couldn't explain. Finally, on a whim, I decided to modify PyInstaller directly and have the build process try the final append a few extra times.
I modified a PyInstaller source file, api.py, to try the final package append up to ten times. After this change, the build process succeeds on the second or third time. With this change, the first or second append attempt usually fails with the same permissions error, but the second or third works, and the executable package is built correctly.
I changed PyInstallers api.py at line 737:
FROM
else:
# Fall back to just appending data at the end of the file
logger.info("Appending %s to EXE", append_type)
with open(self.name, 'ab') as outf:
with open(append_file, 'rb') as inf:
shutil.copyfileobj(inf, outf, length=64 * 1024)
TO
else:
desparation = 10
while desparation:
desparation -= 1
try:
# Fall back to just appending data at the end of the file
logger.info("Appending %s to EXE", append_type)
with open(self.name, 'ab') as outf:
with open(append_file, 'rb') as inf:
shutil.copyfileobj(inf, outf, length=64 * 1024)
desparation = 0
except PermissionError as e:
logger.error(e)
I ran across this same error and found that when I built it in PowerShell with admin rights it worked.
My environment is pycharm uses the venv environment, and there is always a problem with the last open permission. I change the python environment of pycharm to the system environment and run normally.
Use --clean parameter to clean PyInstaller cache and remove temporary files before building.
See : https://pyinstaller.readthedocs.io/en/stable/usage.html#cmdoption-clean
python -m pyinstaller --name "MyApp" "./" --clean
This solved the error for me.
One good solution is to uninstall pyinstaller and install it again :
Step I
python.exe -m pip uninstall pyinstaller
Step II
TRY TO GET AN OLDER VERSION of pyinstaller and its dependencies
python.exe pip install pefile==2019.4.18
python.exe -m pip install pyinstaller==3.6
Step III
try to put the files that you are trying to use with pyinstaller into a new folder for example :
C:\Projects
Step IV
Make an executable in one file
C:\Projects>C:\Python27\Scripts\pyinstaller.exe example_v3.py --onefile
My issue was I was trying to build pyinstaller using a __main__.py inside a folder and invoking pyinstaller on the folder.
Renaming __main__.py to main.py and running pyinstaller on the new main file solved the problem.
Hope this helps.
The error message show "INFO: UPX is not available", you need to import UPX.exe, this problem will be solved.
enter image description here
Related
Good afternoon people.
Once again trying to package kivy for DESKTOP on WINDOWS 10 and to no avail!
I had a lot of errors that I managed to solve without disturbing the order in the groups but this one is phoda with ph.
1 - I create the exe using Auto_py_to_exe and before there is any comment that I should use pyinstaller, I tell you, the same thing happens!
2 - My pyinstaller script is as follows:
pyinstaller --noconfirm --onefile --console --name "TeuCu" --add-data "C: /Users/Elias/Desktop/kv_inventario/inventario/main.kv ;." --add-data "C: / Users / Elias / Desktop / kv_inventario / inventario / images; images /" "C: /Users/Elias/Desktop/kv_inventario/inventario/main.py"
3 - The error is exactly like this, when running the application after it is created it returns this error:
[CRITICAL] [Window] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
File "kivy\core\__init__.py", line 70, in core_select_lib
File "kivy\core\window\window_sdl2.py", line 152, in __init__
File "kivy\core\window\__init__.py", line 982, in __init__
File "kivy\core\window\window_sdl2.py", line 311, in create_window
File "kivy\core\window\__init__.py", line 1268, in create_window
File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
File "kivy\core\image\__init__.py", line 561, in __init__
File "kivy\core\image\__init__.py", line 754, in _set_filename
File "kivy\core\image\__init__.py", line 460, in load
File "kivy\core\image\__init__.py", line 223, in __init__
File "kivy\core\image\img_sdl2.py", line 47, in load
[CRITICAL] [App] Unable to get a Window, abort.
My solution that could possibly work would be this tip that I found in kivy issues:
Kivy issues
This took me to the post below and translating it asks to uninstall the pillow and reinstall with the wheel
python3 -m pip3 uninstall pillow
python3 -m pip3 install --use-wheel pillow
But it didn't.
I would like your help. Who managed to generate an application for Windows with kivy
I'm using Windows 10 to package.
This error is common - Here are some helpful links:
Kivy not working (Error: Unable to find any valuable Window provider.)
Python app not working after using pyinstaller but doesn't give any errors
https://github.com/kivy/kivy/issues/6342
https://github.com/pal1000/save-legacy-intel-graphics
Kivy does not detect OpenGL 2.0
Windows- Pyinstaller Error "failed to execute script " When App Clicked
Unable to get a window, abort
https://pyinstaller.readthedocs.io/en/stable/when-things-go-wrong.html
https://github.com/kivy/kivy/issues/6276
If none of these work, I also made a video on packaging a kivy app to a single exe for Windows: https://www.youtube.com/watch?v=k9Hx0q5Sopg
Please let me know if you succeed. Cheers!
I am having a heck of a time installing an IDE, python and pip to play well across user accounts.
I have started a new job, where I am allowed to work on school/programming stuff at work. I've even been given the go-ahead to install everything I need on my work computer (two nice big monitors!).
I have also been given administrative login, as I can't install anything on my regular account.
So, I log in to the admin account and followed the documentation on how to install Python and Pip for all users:
Check option for install for all uses
Check Add Python 3.8 to path
Select Customize installation
Again select Install for all users
Ensure the installation path is not in a user directory but rather in C:/Programs/Python...
Install PyCharm IDE
Great. Done. I reboot my machine and login to my humble user account and clone a project from GitHub.
Ok, so I want to add a package using pip... First thing I notice is that pip install <package> doesn't work at all. I get a type error.
Next, I try py pip install <package> and that gets things going, but of course fails after downloading the package. I don't have access to install it.
So I read the solution is to use py pip install <package> --user, which proceeds to tell me that installation is complete and successful with one warning:
WARNING: The script f2py.exe is installed in 'C:\Users\WNeill\AppData\Roaming\Python\Python38\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
I find this interesting, since that's not where I installed Python. Also I find it interesting, because I had the installer add Python to the PATH. I verify my python installation is indeed in my machine's "Program Files" and satisfied that it is, I look up the f2py.script and find that it is part of the package I just tried to install.
A little wierded out, I type my import statement. Sure enough. No dice. "no module named numpy"
At this point, I'm a bit tired of running back and forth between two different user accounts repeatedly installing things and uninstalling them. I've been at it for about 6 hours. Is there a way to make python, my IDE and pip all play nicely together or should I just go back to bringing my personal laptop to work and forget my dreams of coding on one big screen with documentation up on the other?
Edit 1: I don't think this matters, but I'm no expert. I'm doing all of this from the PyCharm native terminal which is running Git Bash.
Edit 2: I decided to check my environment variables on my user account (even though they were added to the PATH variable from the admin account. The PATH variable was not set, so I added the the python38 path and he python38/Scripts. Now I am getting a whole new set of errors which, among other things in a two page error report, is telling me that I have to download Microsoft Visual C++. Is this for real?
Edit 3: I have also tried pip install --upgrade setuptools at another user's suggestion. This too fails miserably with error:
Traceback (most recent call last):
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\Scripts\pip-script.py", line 11, in <module>
load_entry_point('pip==19.0.3', 'console_scripts', 'pip')()
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\__init__.py", line 78, in main
return command.main(cmd_args)
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\cli\base_command.py", line 225, in main
session = self._build_session(
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\cli\base_command.py", line 87, in _build_session
session = PipSession(
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\download.py", line 344, in __init__
self.headers["User-Agent"] = user_agent()
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\download.py", line 134, in user_agent
setuptools_version = get_installed_version("setuptools")
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\utils\misc.py", line 902, in get_installed_version
working_set = pkg_resources.WorkingSet()
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 565, in __init__
self.add_entry(entry)
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 621, in add_entry
for dist in find_distributions(entry, True):
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 1886, in find_eggs_in_zip
if metadata.has_metadata('PKG-INFO'):
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 1405, in has_metadata
return self.egg_info and self._has(self._fn(self.egg_info, name))
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 1760, in _has
return zip_path in self.zipinfo or zip_path in self._index()
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 1637, in zipinfo
return self._zip_manifests.load(self.loader.archive)
File "C:\Users\WNeill\PycharmProjects\data-science-at-home\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pkg_resources\__init__.py", line 1594, in load
mtime = os.stat(path).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\WNeill\\PycharmProjects\\data-science-at-home\\venv\\lib\\site-packages\\setuptools-40.8.0-py3.8.egg'
I have a frustrating problem that set me back a day trying to get an executable file from my finished bookstore app.
I used the Pyinstaller --onefile --windowed bookstore.py from the main project menu, also vm/bin/Pyinstaller --onefile --windowed bookstore.py which created the .exe and .app file successfully.
HOWEVER, when running the .app file, nothing happens. It starts, and just disappears.
I ran the core executable from the cli on Mac from the main project folder with open dist/bookstore.app/Contents/Macos/bookstore and, loads of research and over 20 variations of code and file changes later, I got the same same trackback (N.B. different file path for global Pyinstaller) error message back from the console.
Traceback (most recent call last):
File "bookstore.py", line 5, in <module>
File "/Users/jmulhall/Documents/Documents/Python_Project_Folder/Python3_Training/ProjectBookstore/vm/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "tkinter/__init__.py", line 36, in <module>
File "/Users/jmulhall/Documents/Documents/Python_Project_Folder/Python3_Training/ProjectBookstore/vm/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ImportError: dlopen(/var/folders/0d/6l_1mgwn4cxbrx21_nm7l8gh0000gn/T/_MEIHyYK9G/_tkinter.so, 2): Library not loaded: #loader_path/Tcl
Referenced from: /var/folders/0d/6l_1mgwn4cxbrx21_nm7l8gh0000gn/T/_MEIHyYK9G/_tkinter.so
Reason: image not found
[3899] Failed to execute script bookstore
My Mac details are as follows:
MacOs High Sierra V 10.13.3 with a standard HD on a mid 2012 Macbook Pro
My Software versions are python 3.6.4, pyinstaller 3.3.1 , virtualenv 15.1.0, sqllite3 3.19.3
The most promsing fix on github did not work ergo my query on fixing the Pyinstaller issue for mac where it loads the tcl and tk resources. The links I followed are here:
Main Query Link - Github,
Support File Changes Demo for hooks
I created a pyinstaller-hooks folder and inserted the hook and pyruntime hooks file into the folder with the tclResources and tkResources name changes in the files as follows:
This did not work.
And I am still getting the above stack trace despite running the new command, picking up the new pyinstaller-hooks folder files in the main project folder, as follows:
pyinstaller --onefile --windowed --additional-hooks-dir pyinstaller-
hooks --runtime-hook pyinstaller-hooks/pyi_rth__tkinter.py bookstore.py
Why is it still not finding the the new files with Tree() and os.path.join()) functions altered to tkResources/tclResources and thus crashing the app when it tries to launch. I could not test the .exe as I have only a Mac environment so Im only focused on the .app right now. Can anybody help with this?
Nearly forgot, my main project folder view is as follows:
I have a Windows machine running many apps using Python 2. I want to add a new program I wrote using Python 3. To make sure I don't screw anything up, I wanted to use a Virtualenv with Python 3 embedded (Python 3 embed amd64).
So I extracted the embedded python 3 and tried running virualenv with the --python option enabled.
I tried running the virtualenv
python -m virtualenv --python E:\Projects\python3-embed\python.exe E:\Projects\Virtual\
And I got this error:
Running virtualenv with interpreter E:\Projects\python3-embed\python.exe
Using base prefix 'E:\\Projects\\python3-embed'
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\virtualenv.py", line 2328, in <module>
main()
File "C:\Python27\lib\site-packages\virtualenv.py", line 713, in main
symlink=options.symlink)
File "C:\Python27\lib\site-packages\virtualenv.py", line 925, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "C:\Python27\lib\site-packages\virtualenv.py", line 1147, in install_python
writefile(site_filename_dst, SITE_PY)
File "C:\Python27\lib\site-packages\virtualenv.py", line 362, in writefile
with open(dest, 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'E:\\Projects\\Virtual\\python36.zip\\site.py'
I am not entirely sure how can I fix this error. There is a site.pyd file in python36.zip but it seems that virtualenv can't use it.
Sorry in advance
I knew this is not the answer you meant to ask for, but I tried hard that (our) way, and got this solution at last.
TL;DR
Update on 17 December 2021
The download page has been moved to https://winpython.github.io/
, for my purpose, I will download Winpython64-3.10.0.1dot.exe for now. Please don't forget to verify the checksum for the executable package.
End of the update on 17 December 2021
Use the portable installer with postfix "Zero" from WinPython
WinPython64-3.7.0.2Zero.exe(64 bit version, YOU want this)
WinPython32-3.7.0.2Zero.exe(32 bit version)
The Too Long version
What I tried
Yes, I downloaded the python-3.7.0-embed-amd64.zip from this page
Yes, I set it up according to instructions in this page
Yes, it worked as a python interpreter
D:\temp\test>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
>>>
Yes, I installed the package virtualenv
D:\temp\test>virtualenv --version
16.0.0
Then, boom (where you asked)
D:\temp\test>virtualenv ENV
Using base prefix 'd:\\portable\\python-3.7.0-embed-amd64'
Traceback (most recent call last):
File "runpy.py", line 193, in _run_module_as_main
File "runpy.py", line 85, in _run_code
File "D:\portable\python-3.7.0-embed-amd64\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 712, in main
symlink=options.symlink)
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 927, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 1149, in install_python
writefile(site_filename_dst, SITE_PY)
File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 363, in writefile
with open(dest, 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\temp\\test\\ENV\\python37.zip\\site.py'
Seems a problem with virtualenv, searched, got an open issue, and I don't like that long solution.
This is the end of virtualenv.
Then, I tried venv:
D:\temp\test>python -m venv venv
D:\portable\python-3.7.0-embed-amd64\python.exe: No module named venv
Yes, the "built-in module" was lost, and the document for Embedded Distribution doesn't even mention it, just something about Tcl/tk (...), pip and the Python documentation are not included.
This is the end of venv.
Well, start again from my original point
The purpose to choose Embedded Distribution is (just like SOMEBODY):
To make sure I don't screw anything up
this include "don't install anything into my unstable and oversized Windows"
but doesn't necessarily "must use the Official Embedded Distribution"
something portable and trusted is enough, yes Portable Python
but the main page says "Portable Python is not being developed anymore", and provide some choice
after some reading, I figured out, what I want is WinPython, the version with a Zero
ta-da ... That's it.
Something about Embedded Distribution (from official document)
The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.
The embedded distribution is meant to be lightweight. To install a virtual environment, follow these steps.
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Once these steps are done, proceed with the recommended approach and create a virtual environment using the command below. The --system-site-packages is typically used to bring a non embedded distribution packages already in the python install into the virtual environment, but since this is embedded, you can omit. But it won't hurt to have it.
python -m venv --system-site-packages C:\Python\python-3.7.9-embed-amd64\py37venv
My goal is to serve a hello world Django app that uses postgres on an EC2 instance running Ubuntu. I logged in via ssh and cloned a git repo containing a Django project with this requirements.txt:
Django==1.8.2
djangorestframework==3.1.2
psycopg2==2.6
I created a virtualenv and then, when I ran (ec2_deploy_test)ubuntu#ip-172-31-22-100:~/ec2-deploy-test$ pip install -r requirements.txt, this exception was thrown:
Collecting psycopg2==2.6 (from -r requirements.txt (line 3))
/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:90:
InsecurePlatformWarning: A true SSLContext object is not available.
This prevents urllib3 from configuring SSL appropriately and may cause
certain SSL connections to fail. For more information, see
https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning Downloading psycopg2-2.6.tar.gz (367kB)
100% |████████████████████████████████| 368kB 785kB/s Building wheels for collected packages: psycopg2 Exception: Traceback (most
recent call last): File
"/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/basecommand.py",
line 223, in main
status = self.run(options, args) File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/commands/install.py",
line 291, in run
wb.build(autobuilding=True) File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/wheel.py",
line 753, in build
ensure_dir(output_dir) File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/utils/init.py", line 70, in ensure_dir
os.makedirs(path) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 150, in
makedirs
makedirs(head, mode) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 150, in
makedirs
makedirs(head, mode) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 150, in
makedirs
makedirs(head, mode) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 157, in
makedirs
mkdir(name, mode) OSError: [Errno 13] Permission denied: '/home/ubuntu/.cache/pip/wheels/ab'
Then I ran (ec2_deploy_test)ubuntu#ip-172-31-22-100:~/ec2-deploy-test$ sudo pip install -r requirements.txt and psycopg2 installed successfully.
Why would I need root permissions to install a python package in my virtual environment? I am new to Linux and sysadmin in general so all advice is welcome. Thanks in advance.
For some reason you don't have an access to create a directory inside the /home/ubuntu/.cache/pip/wheels/ab. Normally this problem shouldn't appear; anyway, since it happened, just change the rights of the .cache directory recursively. I guess that the problem is an ownership, so try to launch the command sudo chown -R <USERNAME> ~/.cache/pip, where the <USERNAME> supposed to be the name of your user.
An advice — try to not launch an apps from root without a real need in this. Most probably that the directory to which you have no an access was created by some application being run with root rights — and now an ownership messed.
I assume you used virtualenv -p /usr/bin/python3.4 env,
I had the same problem
Its python 3 and might have nothing to do with permissions or root if you tried Angles recommendation and it does not work. You need to install python3-dev ... Or just stick with python2. hope that helps
heres the link: Trouble with psycopg2 in virtualenv python3 for use with Django