AttributeError: module 'os' has no attribute 'getcwd'? - python-3.7

i am trying to run a python program which takes input from the users like,directory name,file name and its content and then i try to create the directory in the current path with the file and then write the data into it but i get an error that "os has no attribute mkdir".
//Code
import os
print(os.getcwd())
class createfile:
__name=''
__file_name=''
__input_text=''
def read_and_create(self):
name = input("Enter the directory name, you want to create: ")
os.mkdir(self.__name)
#sdos.mkdir(self.__name)
self.__file_name=input("Enter the file name, you want to create: ")
f=open(self.___file_name,'w')
self.__input_text=input("Enter the text : ")
f.write(self.__input_text)
f.close()
def read_file_content(self):
x=open(self.__file_name,'r')
print(x.read())
o=createfile()
o.read_and_create()
o.read_file_content()
this is the error i got using Pycharm.
> "C:\Users\Aryan
> Kumar\AppData\Local\Programs\Python\Python37-32\python.exe"
> "C:/Users/Aryan Kumar/Desktop/0/os.py"
> Fatal Python error: initsite: Failed to import the site module
> Traceback (most recent call last):
> File "C:\Users\Aryan Kumar\AppData\Local\Programs\Python\Python37-32\lib\site.py", line 73,
> in <module>
> import os
> File "C:\Users\Aryan Kumar\Desktop\0\os.py", line 2, in <module>
> print(os.getcwd())
> AttributeError: module 'os' has no attribute 'getcwd'
>
> Process finished with exit code 1
this is the error i got using Spyder ide in anaconda environment
runfile('C:/Users/Aryan Kumar/Desktop/0/untitled0.py', wdir='C:/Users/Aryan Kumar/Desktop/0')
C:\Users\Aryan Kumar\Desktop\0
Enter the directory name, you want to create: aac
Traceback (most recent call last):
File "<ipython-input-4-fb1c179833e1>", line 1, in <module>
runfile('C:/Users/Aryan Kumar/Desktop/0/untitled0.py', wdir='C:/Users/Aryan Kumar/Desktop/0')
File "C:\Users\Aryan Kumar\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 709, in runfile
execfile(filename, namespace)
File "C:\Users\Aryan Kumar\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Aryan Kumar/Desktop/0/untitled0.py", line 32, in <module>
o.read_and_create()
File "C:/Users/Aryan Kumar/Desktop/0/untitled0.py", line 18, in read_and_create
os.mkdir(self.__name)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

This is an old question but someone might have the same problem. I also received the following error: AttributeError: module 'os' has no attribute 'getcwd'. This is because the file name is os.py. Problem solved after changing the file name.
Also found that a similar answer also provided in a different question:
https://stackoverflow.com/a/43565408/298160

Use os.curdir() in Python3 instead of os.cwd()

Related

Receiving an error when trying to run chatterbot on pi

I am new to working with Chatterbot. I am attempting to run chatterbot on my raspberry pi 4. After installing it, I attempted a basic program from chatterbot's documentation website:
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Bob')
######### Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)
######### Train the chatbot based on the english corpus
trainer.train("chatterbot.corpus.english")
# Get a response to an input statement
responce = chatbot.get_response("Hello, how are you today?")
print(responce)
When I run this program I get this error message:
Traceback (most recent call last):
File "/home/pi/Matthew.codes/JenkinsProject/chatbot_test.py", line 4, in
chatbot = ChatBot('Bob')
File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/chatterbot.py", line 28, in init
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/utils.py", line 33, in initialize_class
return Class(*args, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/storage/sql_storage.py", line 20, in init
super().init(**kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/storage/storage_adapter.py", line 23, in init
'tagger_language', languages.ENG
File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/tagging.py", line 20, in init
import spacy
File "/home/pi/.local/lib/python3.7/site-packages/spacy/init.py", line 6, in
from .errors import setup_default_warnings
File "/home/pi/.local/lib/python3.7/site-packages/spacy/errors.py", line 2, in
from .compat import Literal
File "/home/pi/.local/lib/python3.7/site-packages/spacy/compat.py", line 38, in
from thinc.api import Optimizer # noqa: F401
File "/home/pi/.local/lib/python3.7/site-packages/thinc/api.py", line 2, in
from .initializers import normal_init, uniform_init, glorot_uniform_init, zero_init
File "/home/pi/.local/lib/python3.7/site-packages/thinc/initializers.py", line 4, in
from .backends import Ops
File "/home/pi/.local/lib/python3.7/site-packages/thinc/backends/init.py", line 7, in
from .ops import Ops
File "/home/pi/.local/lib/python3.7/site-packages/thinc/backends/ops.py", line 15, in
from .cblas import CBlas
File "thinc/backends/cblas.pyx", line 1, in init thinc.backends.cblas
File "/home/pi/.local/lib/python3.7/site-packages/blis/init.py", line 3, in
from .cy import init
ImportError: /home/pi/.local/lib/python3.7/site-packages/blis/cy.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_load_8
I have tried adding storage adapters to the name class, but that did not work. As far as I can tell, I have installed all the dependencies.

gnome.gtk-doc() gives permission denied error in Yocto (do_install)

I am trying to generate HTML docs using meson build. I used gnome.gtkdoc() method for this from meson build system.
Following is my meson.build file
project('mydoc', 'c',
version: '0.1.0')
gnome = import('gnome')
glib_prefix = dependency('glib-2.0').get_pkgconfig_variable('prefix')
glib_docpath = join_paths(glib_prefix, 'share', 'gtk-doc', 'html')
docpath = join_paths(get_option('datadir'), 'gtk-doc', 'html')
content_files = [
'docbook-mydoc.xml',
]
gnome.gtkdoc('mydoc',
main_xml : 'main-doc.xml',
src_dir : [
join_paths(meson.source_root())
],
fixxref_args: [
'--html-dir=' + (gnome.gtkdoc_html_dir(meson.project_name())),
'--extra-dir=#0#'.format(join_paths(glib_docpath, 'glib')),
'--extra-dir=#0#'.format(join_paths(glib_docpath, 'gobject')),
'--extra-dir=#0#'.format(join_paths(glib_docpath, 'gio')),
],
content_files: content_files,
install : true,
install_dir: join_paths(meson.source_root(), 'doc')
)
Above meson.build works fine and can generates HTML pages. I have problem when running above meson.build in Yocto. It gives me Permission denied error while do_install operation.
ERROR: ['gtkdoc-mkhtml', '--path=/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/git/:/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/build/', 'mydoc', '../main-doc.xml'] failed with status 1
Traceback (most recent call last):
File "/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/recipe-sysroot-native/usr/bin/gtkdoc-mkhtml", line 51, in <module>
sys.exit(mkhtml.run(options))
File "/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/recipe-sysroot-native/usr/share/gtk-doc/python/gtkdoc/mkhtml.py", line 93, in run
quiet] + remaining_args + [gtkdocdir + '/gtk-doc.xsl', document])
File "/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/recipe-sysroot-native/usr/share/gtk-doc/python/gtkdoc/mkhtml.py", line 42, in run_xsltproc
return subprocess.call(command + args)
File "/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/recipe-sysroot-native/usr/lib/python3.7/subprocess.py", line 339, in call
with Popen(*popenargs, **kwargs) as p:
File "/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/recipe-sysroot-native/usr/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/home/user/yocto/build-zeus/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/mydoc/1.0.0-r0/recipe-sysroot-native/usr/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: ''
I am not sure why its gave me permission denied error. Any help will be appreciated.
It's a bit suspicious that you are trying to install into source root directory with
install_dir: join_paths(meson.source_root(), 'doc')
Typically, it's just directory name relative to gtk-doc html dir (gnome.gtkdoc_html_dir()) or not set at all - then directory is module
name. So try just remove it...
Update
You might be missing prefix for project html dir (for --html-dir )and it should look like:
'--html-dir=' + join_paths(get_option('prefix'), gnome.gtkdoc_html_dir(meson.project_name()),
Note. And instead of generating gtk doc path, it should be more reliable to use above mentioned function:
'--extra-dir=' + join_paths(glib_prefix, gnome.gtkdoc_html_dir('glib')),
...

supress_callback_exceptions = True no loger works

In an older version of Dash, I used to need to be able to say,
supress_callback_exceptions = True
Since I upgraded to the new version of Dash, now I get an error on that line:
Traceback (most recent call last):
File "dash-yahoo_options.py", line 2109, in <module>
app.config.supress_callback_exceptions = True
File "/home/idf/anaconda3/envs/dash_apps_36/lib/python3.7/site-packages/dash/_utils.py", line 81, in __setattr__
self[key] = value
File "/home/idf/anaconda3/envs/dash_apps_36/lib/python3.7/site-packages/dash/_utils.py", line 106, in __setitem__
raise AttributeError(final_msg, key)
AttributeError: ('Invalid config key. Some settings are only available via the Dash constructor', 'supress_callback_exceptions')
(dash_apps_36) idf#ubvm:~/Downloads$ vi dash-yahoo_options.py
(dash_apps_36) idf#ubvm:~/Downloads$ python dash-yahoo_options.py
Traceback (most recent call last):
File "dash-yahoo_options.py", line 2109, in <module>
app.config.supress_callback_exceptions = True
File "/home/idf/anaconda3/envs/dash_apps_36/lib/python3.7/site-packages/dash/_utils.py", line 81, in __setattr__
self[key] = value
File "/home/idf/anaconda3/envs/dash_apps_36/lib/python3.7/site-packages/dash/_utils.py", line 106, in __setitem__
raise AttributeError(final_msg, key)
AttributeError: ('Invalid config key. Some settings are only available via the Dash constructor', 'supress_callback_exceptions')
In case you missed it in the Dash change log, this misspelled fallback was removed in 1.0.0.
The configuration attribute should still supported (as at 1.6.0), you just need to use the right name.
app.config.suppress_callback_exceptions = True

Docker-compose: AttributeError: 'module' object has no attribute 'ssl'

Today I have tried use docker-compose and got next error:
>>docker-compose
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 9, in <module>
load_entry_point('docker-compose==1.7.1', 'console_scripts', 'docker-compose')()
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 14, in <module>
from . import errors
File "/usr/lib/python2.7/site-packages/compose/cli/errors.py", line 9, in <module>
from docker.errors import APIError
File "/usr/lib/python2.7/site-packages/docker/__init__.py", line 20, in <module>
from .client import Client, AutoVersionClient, from_env # flake8: noqa
File "/usr/lib/python2.7/site-packages/docker/client.py", line 22, in <module>
import websocket
File "/usr/lib/python2.7/site-packages/websocket/__init__.py", line 22, in <module>
from ._core import *
File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 39, in <module>
from ._socket import *
File "/usr/lib/python2.7/site-packages/websocket/_socket.py", line 28, in <module>
from ._ssl_compat import *
AttributeError: 'module' object has no attribute 'ssl'
OS: OpenSuse Leap 42.1
Docker-compose: 1.7.1
Docker: 1.11.2
libopenssl-devel installed
Downgrade OpennSSL to version 1.0.1i-15.1 from 1.0.1i-2.36.1 has fixed my problem.

Jupyter notebook and anaconda

I installed Jupyter in Ubuntu, and I use Anaconda. When I try to open a new empty ipython notebook, I get the error 'NameError: global name 'datetime' is not defined'. I transcribe below the complete error message:
[IPKernelApp] ERROR | Invalid Message
Traceback (most recent call last):
File "/home/luiz/anaconda/lib/python2.7/site-packages/ipykernel/kernelbase.py", line 175, in dispatch_shell
msg = self.session.deserialize(msg, content=True, copy=False)
File "/home/luiz/anaconda/lib/python2.7/site-packages/jupyter_client/session.py", line 870, in deserialize
return adapt(message)
File "/home/luiz/anaconda/lib/python2.7/site-packages/jupyter_client/adapter.py", line 386, in adapt
header['date'] = datetime.now().isoformat()
NameError: global name 'datetime' is not defined
[IPKernelApp] ERROR | Invalid Message
Traceback (most recent call last):
File "/home/luiz/anaconda/lib/python2.7/site-packages/ipykernel/kernelbase.py", line 175, in dispatch_shell
msg = self.session.deserialize(msg, content=True, copy=False)
File "/home/luiz/anaconda/lib/python2.7/site-packages/jupyter_client/session.py", line 870, in deserialize
return adapt(message)
File "/home/luiz/anaconda/lib/python2.7/site-packages/jupyter_client/adapter.py", line 386, in adapt
header['date'] = datetime.now().isoformat()
NameError: global name 'datetime' is not defined
What am I missing?
Oops, I needed to update some iPython dependencies. Problem solved!
Thanks!