To set current working directory in PyDev interactive console - console

I know that when I start the interactive console in pydev using ctrl + alt + enter, the working directory is not the one the project is in. Therefore, I adopted this code when the console starts (which worked):
import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
import os
cwd_path = [path for path in sys.path if 'org.python.pydev' not in path and 'Python3' not in path and 'python33.zip' not in path]
if len(cwd_path) == 1:
os.chdir(cwd_path[0])
However, the problem is it only takes me to the folder of the project, instead of the file. For example, my file is in src//com/main//test//Test.py , and this code will only take me to the folder where src is in. Is there anyway to get around this?
Thanks!
-Shawn

This is not technically a work-around, but I do find that Spyder IDE solves this problem pretty well. I just installed from the WinPython package, and it worked very well for me.
The link to WinPython
I'll still really appreciate it if someone can provide a way to fix it in Eclipse/Pydev - because that's been what I use for all other projects and I really like it. Thanks!

Related

The help systems return "help provider not available"

I'm using visual studio code to program in R and I have recently had trouble using the ?func and ??func command.
When typing something like ?rnorm, the message Couldn't show help for path: /library/stats/html/Normal.html shows up. The path is there and I'm sure R is in the path environment. This is really boggling me.
When I first installed R it was working absolutely fine in VSC but now it does not work. However the function works in the R shell. When I try to navigate to the R extension and click on "Help Topics by Package" it says help provider not available.
The packages/html files are there, but VSC doesn't want to access them.
Please advise what I can do to solve this.
I solved the same issue by checking my environmental variables. The steps I followed:
I added the bin installation file (C:\R\R-4.1.3\bin in my case, or C:\Program Files\R\R-4.1.3\bin) to the path in my user environmental variables. If you have an admin account, then you have to add the bin folder to the system environmental variables.
Check if you can start a R console from any terminal.
If that is positive, then in the Rpath settings for the R extension in vscode write r, or in the settings.json: "r.rpath.windows":"r"
Restart vscode. Check if the help pages are working.
Hope this helps ! Cheers.
This happened to me as well. I googled and tried different things and this works for me:
You need to provide the Rpath for the system you are using in the settings for the vscode R package. For example, for a windows machine, you need C:\Program Files\R\R-4.1.3\bin\x64\R.exe there if you installed the latest R using the default settings, and similarly for other systems.
Hope it helps!

I am trying to convert a python .PY file to .EXE. But the EXE file won't run because of "Fatal Error Detected Failed To Execute Script Error" Help Pls

I am a absolute beginner with Python. What I have done so far is I have installed Python with IDLE, Pycharm, Pygame-zero and Pyinstaller too. I have a (.py) file game I would like to turn into a (.exe) file. So I can release my game for my friends to play.
I have entered this command into CMD window "pyinstaller --onefile -w gamename.py"* (*My game is not really called "gamename". I have called it that in this code above. For this example only.)
When in the file folder of my game and then Pyinstaller converts my file into the (.exe) file. But everytime I try to run this file. It fails with this error message - "Fatal Error Detected, Failed To Execute Script Error".
I have watched all kinds of YouTube videos trying to solve this problem and have tried these following fixes:
Updated Pyinstaller (4.3).
Updated Python (3.9.5).
Changed the path in Enviroment Variables to point to Python39\Scripts and resetting my computer.
Coverted the (.py) file to (.exe) by including the console window. Then after running the program after when the console window disappears. Opening the CMD window again and typing the file directly "gamename.exe" to run.
Installing auto-py-to-exe program.
Each time deleting the Main, Dis and Spec files and moving the (.exe) file into the main file folder. With the resources for the games. Music, Images and Sounds.
Testing out my Python script to check. If it doesn't have any errors while loading through IDLE and it doesn't. It works straight away, I can play my game through IDLE. There is no errors in the code of my game script.
And after trying all of these solutions it still hasn't solved this issue.I still have the same error message appearing when trying to run my game. Now I have found out what the meaning is to this error message that appears. Which is:
"Fatal Error: failed to execute
This means something has gone wrong as it's giving you a visual warning about it; this is not an error, it's a warning; the real error has been printed to stdout/stderr. If you open the executable using the terminal or something else that will preserve the console output, you will most likely see a Python error telling you what went wrong. Fixing this and repackaging is the solution to this issue".
I have remade the (.exe) file including the console window and it does explan what the error is. When I try to run my game, the error comes up as:
"FileNotFoundError: {Errno 2} No such file or directory: C:*****\Local\Temp_MEI58602\pgzero\data\icon.png {4268} Failed to execute script.
Any suggestions? On how to fix this error please. So I can run and play my game outside of Python on any PC.
A Possible Answer:
I have found a webpage that has the possible answer to my problem. But I don't know what they mean, because I am a beginner with Python. Can anybody read this and break it down for me? Here is what it say's:
"Pyinstaller packaging exe, missing icons and other issues
Reason
When the exe runs, it will decompress a resource folder named "_MEI*" to a temporary directory on the computer, and delete it when the program ends.
uses a path like ‘\icon.png’ in the program. When the exe is running, it will only search for its own directory, of course it cannot be found.
Two, the solution
Make sure the picture is in this temporary resource folder
This can be done by editing the'.spec' configuration file to add pictures.
(Note: .spec is the file generated by Pyinstaller last time, in your python project directory.)
These are the three pictures I used, which is actually adding three tuples to the "binaries" list
Before the comma is the address of the picture in the python project, after the comma is the address of the package into the ‘_MEI*’ temporary folder.
I have built an ‘img’ folder to store pictures in it. Just put a dot in the root directory, such as (’./img/info.png’,’.’)
Finally, run when packagingpyinstaller program entry.spec, You can add the picture resource.
(Note: Other external resources can also be added in this way, such as .ini, .txt, .exe, etc.)
Make sure the program can find this path
Because the name of the temporary directory is different each time, a method is needed to dynamically obtain this path.
The code is presented, and the core statement is ‘os.path.realpath(sys.path[0])’.
Python running effect is as follows:
Package it as an exe, drag it to the cmd window and run it."
Here is the link to the webpage to the article. Because it makes use of screenshots that I can't include on this webpage;
(https://www.programmersought.com/article/94965073850/)
Please read this acticle and break it down for me. It does seem to be explaining the solution to my problem. But what does it all mean? What pictures is he talking about? Please explain.
I am not sure why but PyInstaller doesn't seem to bundle everything needed for Pygame Zero, including that icon.png file. The solution is simple, though. You just need to use pyinstaller --collect-all pgzero --onefile -w <scipt_name>. If your game has sounds, images or anything like that, remember to include those specific folders as well using --add-data <file_or_folder>. Also, make sure your script includes the following lines.
import pgzrun
# GAME CODE HERE
pgzrun.go()
I hope it helps, even though it is a little late.

Could not start the julia language server in VS Code

I'm getting this error in VS Code:
Could not start the julia language server. Make sure the configuration setting julia.executablePath points to the julia binary.
In user settings I put
"julia.executablePath": "c:\\Program Files\\Julia\\Julia-0.5.0\\bin\\julia.exe"
which is a correct executable path.
Julia works without a problem in console and VS Code worked fine with older extension 0.4.2. I've tried reinstalling both the extension and VS Code, but it didn't help.
What am I doing wrong?
I had the same problem, just run Julia REPL and switch to pkg mode with ] and add LanguageServer package with add LanguageServer and restart vs code.
VS Code settings don't seem to always play nice with backslashes. Try instead single slashes, even on Windows:
"julia.executablePath": "c:/Program Files/Julia/Julia-0.5.0/bin/julia.exe"
It may, however, also be a problem with the blank in 'Program Files', in which case the legacy 8.3 filename convention could work:
"julia.executablePath": "c:/PROGRA~1/Julia/Julia-0.5.0/bin/julia.exe"
Note that you would typically have both 'C:\PROGRA~1' and 'C:\PROGRA~2' pointing to 'C:\Program Files' and 'C:\Program Files (x86)', respectively. Find the correct one from the console.
Have a look if the 'LanguageServer' package is actually installed/somehow uninstalled, this happened to me. After manually installing it, it was all fine and dandy again.
Indexing all the packages still takes ages, though.
https://github.com/JuliaEditorSupport/julia-vscode/issues/405
This can happen if the VS Code extension doesn't support the current version of Julia.
Also check that the path is pointing to the julia.exe executable inside the bin folder.
C:\Users\yourname\AppData\Local\Julia-0.5.0\bin\julia.exe
because there is also another one that doesn't work.
C:\Users\yourname\AppData\Local\Julia-0.5.0\julia.exe
Reinstalling Julia solved this for me, I tried the previous answers
It is probably due to a SysImage you have compiled and replaced the original sys.dll file with that. Try to check the path C:\Users\User\AppData\Local\Programs\Julia-1.7.3\lib\julia or any other path you have installed Julia and see if a sys.dll.backup exists there, together with a sys.dll file. Rename the sys.dll to sys.dll.old and rename the sys.dll.backup to sys.dll. Then restart julia or VS Code.

What is '.R' folder and where to look for it?

I am a beginner in R. I use Rstudio on my MAC OSX.
I have no idea what does this mean 'create a folder ~/.R and put a Makevars in it.'
I went word by word and tried creating '.R' in my home(~) directory. MAC doesnt allow it saying "You can’t use a name that begins with a dot “.”, because these names are reserved for the system. Please choose another name." ( of course!)
Next I tried to look for .R folder, hoping that it might already be there. But couldn't find it anywhere.
Can anyone please explain where is this '.R' folder on our system? Or how is the whole R folder hierarchy is built.
I tried doing this:
path2 = normalizePath("~/.R")
Warning message:
In normalizePath("~/.R") :
path[1]="/Users/as82986/.R": No such file or directory
setwd(path2)
Error in setwd(path2) : cannot change working directory
Problem is I couldn't even find anything on google because looking for '.R' folder threw pretty vague and unrelated results.
Also, would appreciate if I am not directed to any more documentations. Please. And thank you so much for helping me.
You need to use the Terminal.app to open a Unix console and then type:
$ mkdir ~/.R
The dollar sign is there to remind you that this is not the R console which has a ">" prompt. (Do not type the "$".) You are going to need to learn a few more lessons about the Unix commands if you plan to compile packages from source. I generally run my Finder with ShowAllFiles set to Yes. Do a google search if that is not meaningful to you.

WinPython with PyQt5

I'm trying to get PyQt5 working with WinPython. PyQt5 comes with a readme file for installation, and I have unsuccessfully tried a few combinations of what I thought the first part of the readme tells me to do.
I have:
Windows 7 Home Premium 64-bit
WinPython-64bit-2.7.9.1
Qt 5.4
PyQt-gpl-5.4
PyQt-gpl-5.4 is in the folder (only partially sure that this is where I should have put it)
C:\WinPython-64bit-2.7.9.1\python-2.7.9.amd64\Lib\site-packages\PyQt-gpl-5.4
My current attempt at getting everything working is: I'm trying to run the configure.py file in PyQt-gpl-5.4, but when I do so I consistently get the following error:
Error: PyQt5 requires Qt v5.0 or later. You seem to be using v4.8.6.
Make sure the correct version of qmake is on your PATH.
What I think is the required version of qmake being referred to is in the folder
C:\Qt\5.4\mingw491_32\bin
However, I have no idea how to fix the error by adding the qmake in this folder to PATH. My most recent attempt was to add the folder using Spyder's Tools->PYTHONPATH manager, but this made no difference. I also tried adding it using sys.path.append('C:\Qt\5.4\mingw491_32\bin'), but this didn't work either. I have since removed the folder name from both of these locations.
How do I get PyQt5 working with WinPython-64bit-2.7.9.1, or I think equivalently, how to I get the configure.py file in the PyQt-gpl-5.4 folder to run?
Thanks.
You definitely don't want the source code (i.e. PyQt-gpl-5.4) in the site-packages folder, because that's where the compiled modules will end up. Instead, it should just go in a temporary folder whilst you compile it.
When you run configure.py, you must take care to use the executable for the specific python that you are targeting. I do not know anything about WinPython, but for a normal python installation this means doing something like this:
C:\Python34\python configure.py
As a first step, before attempting to actually compile anything, it would be advisable to take at look at all the configuration options that are available, like this:
C:\Python34\python configure.py --help
(There's also the Installing PyQt5 section in the PyQt Docs).
This will tell you, for instance, that the simplest way to specify the Qt installation you are targeting would be something like this:
C:\Python34\python configure.py --qmake C:\Qt\5.4\mingw491_32\bin\qmake
EDIT:
Sorry, that last part is wrong: the --qmake option isn't available on Windows, so you have to add the directory containing the qmake executable to your PATH. This can be done with the following command:
set PATH=%PATH%;C:\Qt\5.4\mingw491_32\bin

Resources