So, I have Python Portable 2.7.5.1 on my USB (every option installed, including Matplotlib), and whenever I try to run a script with a Matplotlib code, I get this:
TclError: couldn't open "*path*\Portable Python 2.7.5.1\App\lib\site-
packages\matplotlib\mpl-data\images\matplotlib.gif": no such file or directory
The mentioned matplotlib.gif file is in the specified directory,
so I don't know what to do to make it work...
Related
I'm attempting to use the Python module pydeps (installed with mamba install pydeps) to analyze the dependencies in my project. However, when I run the command pydeps main.py (perhaps "main.py" is not the most informative script name ever), I get the following output:
<pydeps_folder>/pystdlib.py:17: UserWarning: stdlib_list does't support Python 3.10 yet, pydeps will use symbols from 3.9 for now.
warnings.warn(
ERROR: While opening '<working_directory>/main.svg': [Errno 2] No such file or directory: 'xdg-open' (can be caused by not finding the program to open this file)
When I then run the command firefox main.svg, I see a graph containing some of the files in my project, but not all of them, so it seems like pydeps succeeded partially. Do I need xdg-open for pydeps to work? Or is there any way I can make pydeps work by telling it to just generate the svg file and not try to open it?
Answer
xdg-open in this context is used to open the main.svg resulting file. It is a linux utility that opens a file or URL with a preferred/default application. (i.e jpg -> image viewer). In this case it tries to open main.svg with your preferred image/svg file viewer.
It sounds like it errors out when trying to open the final result main.svg, which is what you're doing by executing:
firefox main.svg
Therefore I don't think its a partial result of the dependencies.
References:
xdg-open docs: https://linux.die.net/man/1/xdg-open
I just switch laptops and everything seems to be normal except this. When I open CMD and try to run a file like py filename.py
it comes up with an error
C:\Users\john\AppData\Local\Programs\Python\Python37\python.exe: can't open file 'filename.py': [Errno 2] No such file or directory
It defaults to the python.exe file. It does it for every file that I try to run as well. I am in the correct directory (the directory where the actual file is in) but it keeps defaulting to that error. I am running windows 10 with python 3.7.3.
You may have to change the default directory where your terminal looks for the python.exe file and its packages. You must change both. One variable points to the python[version] folder and the other points to the python[version]\scripts folder.
This page shows you how to redirect your terminal in windows:
https://superuser.com/questions/1399544/how-to-change-default-python-executable-on-windows-10/1399546
Another tip is that you must change these two identical directories for both the "user variables" and the "system variables" listed in the section below it. I believe the Python installation has probs with this, especially if it's a reinstall or a failed update. And on Windows in general.
Best,
I am trying to run python on Ubuntu. ADDED: It's a double boot system with Windows.
If I type python on the shell, it opens python. But I want to run a python file.
I have my python (.py) file saved on windows Desktop.
On Windows when I run a .py file in my command prompt, I just have to change directory to Desktop then type python myfile.py and the code runs successfully.
When I try to do that same thing in Ubuntu, it does not work. I made a Desktop directory in Ubuntu using the mkdir function.
Now, when I type python myfile.py, I get the error:
python: can't open file 'myfile.py': [Errno 2] No such file or
directory
I tried typing python on the Ubuntu shell then dragging the myfile.py file (~$ python C:\Users\username\Desktop\myfile.py), it used to run and then close the answer right away, but now I would get the error
python: can't open file 'C:UsersusernameDesktopmyfile.py': [Errno 2]
No such file or directory
Can anyone tell me what are the exact steps I need to do to fix this?
EDIT:
Here is what I am writing from the answers below:
~$ python /home/username/Desktop/myfile.py
Yet, I am getting this error:
python: can't open file '/home/username/Desktop/myfile.py': [Errno 2] No such file or directory
EDIT 2**
So here is something new:
if I write
python /home/username/Desktop myfile.py
I get this error
/usr/bin/python: can't find 'main' module in '/home/username/Desktop
If I write
python /home/username/myfile.py
I do not get an error, but I do not get any output either. Ubuntu just goes to the next line $
Strange on Ubuntu your path starts with c:\...
On Ubuntu user folders are usually in /home, user folder can be referenced by ~, so IMHO python ~/Desktop/myfile.py should work in your environment.
EDIT: noted you made Desktop folder, not original Desktop, that way when you are in that folder type pwd it will show full path, then put it in python PATH/myfile.py (and just in case you may type ls to show list of files in current folder on Linux to check you are indeed in the right folder where your program is).
ADDED: after discussion it turned to be double boot system, mount showed mounted windows disk and file.py was found and run!
Backslash '\' is an escape character, in Unix it will not be used if you put it in a path. It results in your error of path not found.
Use slash '/', your code should run.
It is weird that you have a path for windows, in Unix you should not have this type of path...
Open a terminal, go to the folder with your python script. Use pwd in the terminal to know the exact location and then copy the path and use the following (I take an example here):
python PATHTOYOURPYTHONSCRIPT/mypythonscript.py
You're trying to use windows path representation in Linux. Windows and Linux has different path representations.
In windows, you can use C:\ but in Linux it's just a / which is used to denote the root directory.
In the terminal, type 'pwd' where your python file is present in Ubuntu and you'll see the output as '/home/username/Desktop' which is not like windows.
So you need to run like, 'python /home/username/Desktop/my file.py'.
If you need to access the file present in the windows partition, you need to mount the windows partition. This can be done using the Files app present in Ubuntu. After that, you can navigate to /mnt/media/ and find your file.
I am very new to this and struggling with the basics. I have a csv file /home/emily/Downloads/Roger-Federer.csv The textbook says that I need to "extract the file and download it to my current directory" on JupyterLab (I am using Python). What does this mean? How do I do this? Thank you
Every running program, including JupyterLab, has a "working directory" which is where it thinks it is on your computer's file system. What exactly this directory is usually depends on how you launched it (e.g., when you run a program from terminal, its working directory is initially the folder your terminal was in when you ran the command, but it's possible for a program to change its own working directory later).
Your file path indicates you're on Linux, so I'd suggest opening a terminal in your JupyterLab and running pwd to have it print out its current directory. (You can also run !pwd in any open notebook if that's easier.) You should then copy your CSV file to that directory.
If you do that, then from your Python code, you can just open the file locally, like open('Roger-Federer.csv') or pandas.read_csv('Roger-Federer.csv'). You don't have to move the file to open it from Python, though, you can just give it the entire file path, like open('/home/emily/Downloads/Roger-Federer.csv'), and that'll work just fine too.
Our Programs is not always a Python source file !.
The Python may be associated with a file or an image,
that is located inside the source of the application to the file path inside the package.
For example, when setting the application icon in Tkinter Or Include image for app background
root.iconbitmap('favicon.ico')
PhotoImage(file = 'python_logo.gif')
In Pyinstaller only the source file expires in the exe format.
If the program contains a file or image path inside the source, then the program will not be executed , In that event,The source of the application and files are in a package (on a route).
Please provide a solution to this problem, So as possible convert a package containing source and file into exe
1-Install cx_Freeze, (open your command prompt and type pip install cx_Freeze
2-Install idna, (open your command prompt and type pip install idna.
3-Write a .py program named myprogram.py
4-Create a new python file named setup.py on the current directory of your script.
5-In the setup.py, code below and save it.
6-With shift pressed right click on the same directory, so you are able to open a command prompt window.
7-In the prompt, type python setup.py build
8-If your script is error free, then there will be no problem on creating application.
9-Check the newly created folder build. It has another folder in it. Within that folder you can find your application. Run it. Make yourself happy.
this works on python 3.5 and above!
Add heres the open source project to convert to exe
https://github.com/brentvollebregt/auto-py-to-exe
I have not used Pyinstaller myself but in cx_Freeze I know you can include none project files like images in the setup file. With Pyinstaller you want to look into the spec file. Here is a link to the docs where it talks about added files to project. https://pythonhosted.org/PyInstaller/spec-files.html#adding-files-to-the-bundle I hope thisis of some help.