Running Python Example Code - python

I apologise if this is too basic for StackOverflow, but I am currently running Anaconda v3.6.4 and I am trying to get the first example code from the ML: A Probabilistic Perspective GitHub to work but I have no idea how.
On the GitHub read-me, it says;
"You should run the code from the repo root ('pyprobml' directory) using module execution, e.g.
python -m examples.LMSdemo
The example I am trying to run is in examples/mnist1NNdemo.py in the GitHub directory
I have tried using the Anaconda Prompt, Spyder and even rewritten the code but I can't see to get it to run this line / code.
I wish I could provide an example but I am unsure how to even open the code correctly!
If you can share how to get the code to work using Anaconda, then I'd be so grateful - I'm at my wits' end!
https://github.com/probml/pyprobml

Ok, so in the future you would be advised to break your question down into smaller parts. The problem you require an answer to in your question is a different one then your current error (as you mentioned only in the comments to your question) is indicating.
The error you are getting (python is not recognised) already has an answer [here][1]. Which I will not repeat here since it does not relate to your question.
Once you've managed to get Python added to your PATH simply navigate to the folder C:\pyprobml-master (assuming this is indeed the checkout location of the repo on your system? - I am assuming based on the comments to the main question) and execute the demo via python -m examples.mnist1NNdemo.
As an alternative you could also navigate to C:\pyprobml-master\examples and run python mnist1NNdemo.py

Related

How to redirect a python.exe within a pre-existing venv's .env file

Recently I uninstalled python and then reinstalled it to see what affects it would have on my code and ensure that I knew how to fix any path or directory issues. I mostly succeeded but am having trouble within my venvs. Testing out a basic django app I made any of my python manage.py ... code returns the error No Python at '"C:\Python311\python.exe'.
After doing some research it appears that the issue is that within .env\scripts there are two files called "python.exe" and "pythonw.exe" are causing the problem because they are trying to access a python.exe that no longer exists. (Note this is my understanding based off of pythons venv document and I could be incorrect)
My question is what is the best way to deal with this issue. I see two options but am not sure how to accomplish either.
Fully reset the .env folder so it points to the correct python.
Just change those two files so they point to the correct instance of python.
So far the only things I have tested are running code outside of venv's entirely and creating new ones to run the code from. Both work totally fine so it is definitely something from the historic venvs.
I have also looked at this question and I believe the two to be related but could be mistaken. Unfortunately it does not seem an answer was given there.

How to setup python 3.9 on my windows command prompt? It shows an error python not found

I am trying since many hours, after watching several tutorials and reading many blogs I've setup variables as shown by them. Tried all of their methods to setup python3.9 on my windows cmd, but failed. I'm sharing some screenshots of my system variables and other things, please look into the problem and help me.
When you want to share on your post the errors you are getting, please insert them using the Code Sample function so that we can clearly read your errors and have a clear look at your situation.
Anyways, when you first install Python you have to option to automatically add Python to PATH, try uninstalling and checking that option.
If this doesn't work, paste inside your post the error you are getting.
EDIT: Can you share a screenshot of your Python directory?

python power shell issues

Edited to include a specific example
I am learning to use python and work in a windows 10 environment (although on 3 separate computers). I have gotten past the "add python to %PATH% issue" but continue to see odd outcomes when I call simple scripts from powershell compared to running them from the python terminal. For example, I often see that lines of code are duplicated, even simple print statements. A second repeating issue is that some (but not all) modules work fine in the python terminal but can't be found when running a script from powershell, despite using pip install within powershell to install it in the first place.
Rather then seeking help on a specific issue, I'm hoping for some guidance into how powershell and python interact that might help me understand or identify some commonalities in these issues I keep experiencing that are common from within powershell. If thats as simple as redirecting me towards another source even that'd be apprecaited. But my search results always turn up the common issue of powershell not knowing what python is, and needing to add python to the PATH. But as indicated, I have already gotten past this and can get %50 of my python to work from powershell. There must be something else perhaps obvious to others that I'm missing that can help me understand why some things aren't working while others are.
Thanks for taking the time to consider my problem and any advice is greatly apprecaited.
Here is an example from some code I am trying to get working, but in troubleshooting I have taken out a lot of code and am now only running what is shown that defines a dataframe and a print statement. Everything works line by line in python, but when I call the script from powershell, the print statement executes twice.
#!/usr/bin/python3
import pandas as pd
joedata = {'fpr': [0.2,0.4,0.8], 'tpr':[0.9,0.5,0.1]}
joeframe = pd.DataFrame(data=joedata)
print(joeframe)
Concerning modules, you probably have multiple versions of Python installed on your system. Calling pip in the Powershell doesn't mean that it will install for the Python installation which is called by default when you execute Python in the Powershell. So you should try to figure out on which version pip is installing packages and which version is actually used when executing a script.
EDIT: I tested the example that you gave in Powershell and I don't have the problem, it's working fine.
Moreover, for me, without doing any special configuration, in Powershell the commands pip and python refer to the same version of Python. If by default everything is ok, you should consider uninstalling Python and just running the installer again and let it manage the PATH, etc.

Flask mega tutorial part 5 error

Im going through the Microblog tutorial for Flask designed by Miguel.
I made it to part 4 without any issues. Everything ran in the end of part 4.
I started having issues in part 5. After a couple of tries and trying to troubleshoot with the comments in the page, I was not able to finish the exercise.
Thinking it was me, I deleted all of my project and replaced them with the zip downloadable in the page for the exercise. I still get the same error, so the problem is not the code itself.
I get the following error when running views.py:
Link to image on imgur (couldn't post it here due to not having enough reputation)
Here are the libraries I have installed:
Link to image on imgur (couldn't post it here due to not having enough reputation)
My setup:
I am using Pycharm to run the files. This machine runs Windows and I found that Pycharm is the most efficient way to run things without dealing with issues with the cmd line.
Python 3.4
virtualenv created by Pycharm
the code can be found on github: github.com/pdgonzalez872/microblog
Potential cause of the problem:
The problem may be with the path that I have set up (but why did it work until part 4?)
The code itself (maybe something was updated in flask/other libraries since the post?)
views.py isn't meant to be launched separately, there is run.py file to start the project.
Also, it uses relative imports (those with dots before module names), which don't work when you use them in a script passed to the interpreter and used as main. Sorry, I can't explain it well, but maybe you will be interested in those links:
https://docs.python.org/2/tutorial/modules.html#intra-package-references
How to do relative imports in Python?

Python3/MacOSX integration into pycharm

I have had trouble setting up the pycharm ide on my macosx10.7 with python3..
I have scoured every resource available and tried hundreds of approaches, at this point I must accept my incompetence and seek help via this channel.
In my research, I notice a lack of ground-up explanations on python integration into macosx and how to configure pycharm to import modules, run code within the editor, etc. If i ever solve this I will make a very detailed tutorial.
I have imported python3 successfully, it looks like it is linked appropriately from /sys/lib/frameworks to /usr/lib ...etc -- version control is working just fine.
I think my issue is either in setting environmental variables (tried the program to fix this and tried macports) and in the script needed to execute. it will catch errors throughout but final product does not run in python and returns printout of :
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2 /Users/anon/Desktop/pythonpractice/Py_Ex/classes.py
Process finished with exit code 0
i really need to get this configuration sound for my python programming class. please help (I've been through every line of pycharm website) .. preferably is there a way to map it via terminal? thanks for anyone who took the time to read this.
Summary of the discussion above:
Python 3.2.2 installation was broken on this Mac, installing ActiveState Python 3.2.2 from scratch and configuring it in PyCharm has fixed the problem.
Python path to be used in PyCharm settings: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3
Incompatible third-party plug-ins may break PyCharm, uninstall/disable them in Preferences | Plugins.
Ensure the latest PyCharm version is installed.
User's code depends on the graphics.py module which was not in the project or in the PYTHONPATH. Putting it into the project has solved the problem.
Most likely the wrong Run/Debug configuration was used in PyCharm, the easiest way to run or debug such scripts is by using the editor context menu Run and Debug actions. PyCharm creates the configuration automatically and debugging works fine as shown of the screenshot:
If one wants to configure and debug it, he can use the code.zip file to get started.
Sorry for the comments mess above, but it was not possible to move it into chat as user had only 1 reputation point, hence not able to use the chat feature of StackOverflow.

Categories