`os.listdir` throws Error2 for `~` [duplicate] - python-3.8

This question already has answers here:
os.makedirs doesn't understand "~" in my path
(3 answers)
Closed 2 years ago.
python version: 3.8
OS: Manjaro KDE
When I called os.listdir('/home/user_name'), it worked fine.
However, when I called os.listdir('~'), it threw FileNotFoundError: [Errno 2] No such file or directory: '~'.
Why os.listdir failed to understand ~?

It's a Bash feature called "tilde expansion". It's a function of the shell, not the OS.
Thus, the os package of python does not recognize ~

You can use it like this :
p = os.path.expanduser('~')
os.listdir(p)
You may refer these links :
Python's os.makedirs doesn't understand “~” in my path
From documentation

Related

Windows 10 pyinstaller tensorflow missing modules

I try to deploy a model with pyinstaller and when i run it i get the following error.
ModuleNotFoundError: No module named
'tensorflow.python._pywrap_tensorflow_internal'
Tensorflow 1.7.0
cudnn64_7
CUDA 9.0
Python 3.6
You can resolve this issue by simply renaming the file _pywrap_tensorflow_internal.pyd contained in the dist folder to tensorflow.python._pywrap_tensorflow_internal.pyd.
I still have to figure out how to tell pyinstaller the "correct" module name.
( Workaround for Python 3.5 only )
Building off of Jascha's solution, a work around is to manually fetch the file __python._pywrap_tensorflow_internal.pyd from
PathToAnaconda3/env//Lib/site-packages/tensorflow/python/__python._pywrap_tensorflow_internal.pyd
and rename it into tensorflow.python.__python._pywrap_tensorflow_internal.pyd
Then this renamed file can be moved into the exe file by :
pyinstaller -F <name of python file> --add-data "pathToFile/tensorflow.python.__python._pywrap_tensorflow_internal.pyd";.
The flag --add-data takes two arguments separated by semi colon
--add-data source_path;destination_path_inside_exe

Moonscript CLI launch error with Lua 5.3 on OSX

I'm on OS X 10.11.1 running the latest version of X Code. I installed Lua 5.3 today from source with no problem. Seems to work correctly. No errors installing luarocks and then using it to install moonscript. However, both moon and moonc give the following error when invoked from the command line:
$ moon
/usr/local/bin/lua: /usr/local/share/lua/5.3/alt_getopt.lua:24: attempt to call a nil value (global 'module')
stack traceback:
/usr/local/share/lua/5.3/alt_getopt.lua:24: in main chunk
[C]: in function 'require'
/usr/local/lib/luarocks/rocks/moonscript/0.4.0-1/bin/moon:2: in main chunk
[C]: in ?
Looking at alt_getopt.lua shows that it is indeed using the now-defunct 'module' keyword. The GitHub project for this module appears to be dead with no action in the past 3 years.
How should I proceed to get Moonscript working on my system?
Yes, as you noted, module has been deprecated for quite a while and was only working with earlier versions because of compatibility switches.
You can comment out the line 24 in alt-getopt and add the following line to the end of the alt-getopt.lua file: return {get_opts = get_opts, get_ordered_opts = get_ordered_opts}.
This should make this module Lua 5.2/5.3 compatible (I haven't checked if there are any other compatibility issues with using Lua 5.3 though).

package ‘RMySQL’ is not available (for R version 2.15.3) [duplicate]

This question already has answers here:
How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?
(18 answers)
Closed 8 years ago.
I have tried installing RMySQL for three versions of R, but I'm running into same warning message, that RMySQL is not available for that version.
Please, help me out.
Thanks.
install.packages("RMySQL",type="source")
Warning in install.packages("RMySQL", type = "source") :
'lib = "C:/Program Files/R/R-2.15.3/library"' is not writable
--- Please select a CRAN mirror for use in this session ---
also installing the dependency ‘DBI’
trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/DBI_0.2-7.tar.gz'
Content type 'application/x-gzip' length 194699 bytes (190 Kb)
opened URL
downloaded 190 Kb
trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/RMySQL_0.9-3.tar.gz'
Content type 'application/x-gzip' length 165363 bytes (161 Kb)
opened URL
downloaded 161 Kb
<some text missing>
* DONE (DBI)
* installing *source* package 'RMySQL' ...
** package 'RMySQL' successfully unpacked and MD5 sums checked
checking for $MYSQL_HOME... C:\Program Files (x86)\MySQL\MySQL Server 5.6
ERROR: compilation failed for package 'RMySQL'
* removing 'C:/Users/Chanchal/Documents/R/win-library/2.15/RMySQL'
1: running command 'C:/PROGRA~1/R/R-215~1.3/bin/i386/R CMD INSTALL -l "C:\Users\Chanchal\Documents/R/win-library/2.15" C:\Users\Chanchal\AppData\Local\Temp\RtmpErKHEX/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1
2: In install.packages("RMySQL", type = "source") :
installation of package ‘RMySQL’ had non-zero exit status
> install.packages("RMySQL")
Installing package(s) into ‘C:/Users/Chanchal/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
package ‘RMySQL’ is available as a source package but not as a binary
Warning message:
package ‘RMySQL’ is not available (for R version 2.15.3)
I have tried to install RMySQL for R version 3.1.0 on Windows platform. It did not work either. I ran into pretty much the same problem as yours. After reading the documentation for RMySQL package and googled around, I realized that installing RMySQL is very difficult on Windows since it does not have a binary file for Windows as stated in your output.
Instead of RMySQL, I installed RODBC package following instructions here: http://passionfordata.blogspot.com/2012/04/how-to-integrate-r-with-mysql-database.html
RODBC also allows you to connect R to MySQL database, with less trouble and much easier to set up. If your purpose is to connect to MySQL and open to using packages not limited to RMySQL, I would recommend RODBC.

web application-file upload [duplicate]

This question already has answers here:
Get full path of a file with FileUpload Control
(18 answers)
Closed 8 years ago.
I am developing an web application. I am using file upload control to browse files. i have xls file in C:\Mailid.xls path. When i use FileUpload1.PostedFile.FileName command i was get the full path(C:\Mailid.xls).
Today I installed IE 8 After the installation I unable to get the full path of the file what could be the problem Event I uninstalled IE 8. Currently I am using IE 7.
how can i get the fullpath(C:\Mailid.xls) in my project.
Regards
Dhanraj.S
Have you tried using
System.IO.Path.GetFullPath( ... )

Jython - javaos.getenv() gives "Failed to get environment, environ will be empty"

Whenever I run any jython program in Eclipse, I got the following error in the beginning of the output:
" Failed to
get environment, environ will be
empty: (0, 'Failed to execute command
([\'sh\', \'-c\', \'env\']):
java.io.IOException: Cannot run
program "sh": Crea teProcess error=2,
The system cannot find the file
specified')
First, my environment is:
Windows 2008
JDK 1.6.0u10
jython 2.2.1
I did some digging, and I realized that this message is produced in the function javaos.getenv().
Whenever I call the javaos.getenv() function, it throws the following error:
C:\jython2.2.1>java -jar jython.jar
import javaos
print javaos.getenv("user.name")
Failed to get environment, environ
will be empty: (0, 'Failed to execute
command ([\'sh\', \'-c\', \'env\']):
java.io.IOException: Cannot run
program "sh": Crea teProcess error=2,
The system cannot find the file
specified')
This is strange, because I'm currently using a Windows machine, not an Unix.
Try to uncomment and change the os setting in the 'registry' file
(it is in the same directory as your jython.jar / i hope)
# python.os determines operating-specific features, similar to and overriding the
# Java property "os.name".
# Some generic values are also supported: 'nt', 'ce' and 'posix'.
# Uncomment the following line for the most generic OS behavior available.
#python.os=None
python.os=nt
# try nt or dos
Interesting. Well, I seem to have found the relevant code here:
http://www.koders.com/python/fid4B7C33153C1427D2CE19CE361EA9519D1652F802.aspx?s=self
If you look towards the bottom, it seems when setting the environment command jython thinks your os is posix. You say you're using "Windows 2008". I'm not sure what that is. Do you mean Windows Server 2008? If so, it's quite new and if you look at the _getOsType function in the same module, it looks like it might be too new for that module. You may need to upgrade to the most recent version of jython or Eclipse. But it's quite possible they haven't yet released a version that supports this OS. If that's the case, you may need to just report the bug to them.
I'm running on Windows 7.
I'm running Jython as a script in the Websphere wsadmin tool.
I encountered this same error.
I cut-n-pasted these lines from javaos.py into my script:
os or sys.registry.getProperty( "python.os" ) or \ java.lang.System.getProperty( "os.name" )
and it returned "Windows Vista".
So I performed the same surgery as suggested above, ie., add Windows Vista to javaos.py and that solved my problem.
I ran into the same error, using Windows Vista, and Jython 2.5.1, under Eclipse/PyDev By editing javaos.py, to include "Windows Vista" in the OR statement in getOsType,;
I fixed the error. (I've filed a bug with the fix under the PyDev Tracker at SourceForge.)
Details:
I installed the full version of Jython, and that did not help.
I also tried editing the "registry" file in the Jython tree. That did not help either.
Then I looked at the files in:
C:\eclipse-platform-3.5-win32\eclipse\plugins\org.python.pydev.jython_1.4.8.2881\Lib
to find "javaos.py" and added a bit of code to read:
def _getOsType( os=None ):
os = os or sys.registry.getProperty( "python.os" ) or \
java.lang.System.getProperty( "os.name" )
_osTypeMap = (
( "nt", r"(nt)|(Windows NT)|(Windows NT 4.0)|(WindowsNT)|"
r"(Windows 2000)|(Windows XP)|(Windows CE)|(Windows Vista)" ),
( "dos", r"(dos)|(Windows 95)|(Windows 98)|(Windows ME)" ),
( "mac", r"(mac)|(MacOS.*)|(Darwin)" ),
( "None", r"(None)" ),
( "posix", r"(.*)" ), # default - posix seems to vary mast widely
)
for osType, pattern in _osTypeMap:
if re.match( pattern, os ):
break
return osType
I've used this hack from Dave Brands blog: http://dbrand666.wordpress.com/2010/04/08/fix1/
try:
import javaos
if javaos._osType == 'posix' and \
java.lang.System.getProperty('os.name').startswith('Windows'):
sys.registry.setProperty('python.os', 'nt')
reload(javaos)
except:
pass