Error with `pip freeze > requirements.txt` - python

I'm going through the Python Crash Course book and I'm on the section on deploying my app to Heroku. When trying to create the requirements.txt file, I get this error:
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
OSError: [Errno 9] Bad file descriptor
I'm on windows and using the venv module. Running the command from the command prompt.

Double quote is not required .and put >> instead of > .

Related

ansible via virtualenv gives ERROR: [Errno 21] Is a directory

I have an issue globally on my iMac ( M1 incase it matters )
where the commands exit with import ansible module is missing
So I tried installing a tmp dir with virtual env and tried using Ansible from there w/o luck.
I'll start from the error:
$ ../venv/bin/ansible-inventory
ERROR: [Errno 21] Is a directory: '/private/tmp/testansible/z'
File structure is like this:
~/$ cd /tmp
tmp$ mkdir testansible && cd $_
testansible$ mkdir z
testansible$ virtualenv venv
testansible$ venv/bin/pip3 install ansible
Then in a different directory i'm trying to use it:
testansible$ cd z
z$ ../venv/bin/ansible-config init > ansible.cfg
Then running any ansible command gave me tons of errors:
ERROR: Invalid settings supplied for DEFAULT_GATHER_TIMEOUT
ERROR: Invalid settings supplied for DEFAULT_NULL_REPRESENTATION
ERROR: Invalid settings supplied for DEFAULT_REMOTE_PORT
ERROR: Invalid settings supplied for GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODES
Which is strange by itself because their comments says that if there's no value - it will take some default from somewhere
Each one I "resolved" by commenting them out
Then the command worked:
z$ ../venv/bin/ansible-config init > ansible.cfg
But every other ansible command i'm trying to execute gives the same error:
z$ ../venv/bin/ansible -i inventory.hosts
ERROR: [Errno 21] Is a directory: '/private/tmp/testansible/z'
z$ ../venv/bin/ansible-inventory -i inventory.hosts
ERROR: [Errno 21] Is a directory: '/private/tmp/testansible/z'
Any ideas ?
Edit
Thanks to the comment below the issue was this line in the ansible.cfg file:
# (path) File to which Ansible will log on the controller. When empty logging is disabled.
log_path=
Commenting out this line - and the ansible commands started working.
I'm not sure , why across the file it says: When empty logging is disabled - but it's not disabled, it throws an exception. so as all the above variables, they don't really have a default value - they are just getting in the way

Subprocess: Permission and No such file or directory error messages

I'm using Python 3.7 with Idle on a Mac running OS 10.15.4 and am trying to learn the basics of subprocess, with little success despite much effort.
import subprocess
subprocess.Popen('/Applications/Safari.app')
This results in a lengthy error message ending with
PermissionError: [Errno 13] Permission denied: '/Applications/Safari.app'
Removing the first backslash and instead using
subprocess.Popen('Applications/Safari.app')
results in
FileNotFoundError: [Errno 2] No such file or directory: 'Applications/Safari.app': 'Applications/Safari.app'
When I replace Safari with TextEdit, which I'm more interested in using, I receive the second of these error messages regardless of whether I include a backslash.
Use the full path to the executable:
subprocess.Popen('/Applications/Safari.app/Contents/MacOS/Safari')
<subprocess.Popen object at 0x1023414f0>
Alternatively there is the webbrowser module:
>>> import webbrowser
>>> s = webbrowser.get('safari')
>>> s.open('https://google.com')

Mac subprocess run with full path doesn't work

when I run the followin command in terminal it works, and starts application.
/Users/Someone/Documents/SomeApp\ v2.app/Contents/MacOS/SomeApp
But when I do the following in python, then run it:
import subprocess
subprocess.run(['/Users/Someone/Documents/SomeApp\ v2.app/Contents/MacOS/SomeApp'])
I get the following error msg.:
File not found error: [Errno 2] No such file or directory:
'/Users/Someone/Documents/SomeApp\\ v2.app/Contents/MacOS/SomeApp'
It didn't need the '\' in the string.

AttributeError: module 'os' has no attribute 'chroot'

Below is my very basic code running in spyder & python is choking, what am I doing wrong?
import csv,os,sys
path = os.getcwd()
print (path)
os.chroot(path)
I get following error message:
os.chroot(path)
AttributeError: module 'os' has no attribute 'chroot'
One possibility is that your operating system is Microsoft Windows, for which os.chroot() is not available.
Did you name your file os.py? If you did, it is shadowing the stdlib os module. Change the name of your file and delete os.pyc or __pycache__.
Do print os or similar inside the script to see the file path Python is using to get the os module.
I have checked your code, and there is no any ERROR
but i see this message:
PermissionError: [Errno 1] Operation not permitted: '/home/beenj/Documents'
means we must run python3 with sudo ==> sudo python3
then enter above code...
or run compiled Python application (after completing ) in SuperUserDO (sudo)

Error integrating Pylint on Wing IDE

After successful installation on Pylint on my Windows OS, I am able to run it on command prompt to check any python file.
But when I integrate PyLint on Wing IDE v 5.0, I am getting below error on checking any python file
Error executing PyLint: Command failed with error=None, status=2; stderr:
python: can't open file 'C:\Python27\Scripts\pylint': [Errno 2] No such file or directory
Am I missing something to install or pre-configure. I have set the location of Pylint.bat in PATH variable already.

Categories