Invalid syntax with installed package python - python-3.x

I have installed a package named 'Spexxy' with python3 setup.py install which worked fine.
Now, I am trying to use it, so with ipython3 I import the package as follow import spexxy which also works fine, but when I try to use the different tools available in this package, I keep getting the error invalid syntax while I am following the documentation of the package, for example:
I want to creat a grid as specified in the documentation, using spexxytools grid create, here is what I do:
spexxytools grid create --from-filename "lte(?P<Teff>\d{5})-(?P<logg>\d\.\d\d)(?P<FeH>[+-]\d\.\d)(\.Alpha=(?P<Alpha>[+-]\d\.\d\d))?\.PHOENIX"
I get the error:
File "<ipython-input-17-e08367969322>", line 1
spexxytools grid create --from-filename "lte(?P<Teff>\d{5})-(?P<logg>\d\.\d\d)(?P<FeH>[+-]\d\.\d)(\.Alpha=(?P<Alpha>[+-]\d\.\d\d))?\.PHOENIX" .
^
SyntaxError: invalid syntax
The documentation is present here: https://spexxy.readthedocs.io/en/2.1/
Can you tell me why ? Thanks

That's shell syntax. Call it from IPython by prepending an exclamation mark:
!spexxytools grid create --from-filename ...
Based on the documentation, the output will be a file called grid.csv.
If you actually want to use spexxy's Python API, see the API Reference

Related

ModuleNotFoundError: No module named 'gather_keys_oauth2'

I am trying to create a Python Script to get my hands on my Fitbit data so that I can alternately integrate it with another API. I have been following the instruction on this website https://towardsdatascience.com/collect-your-own-fitbit-data-with-python-ff145fa10873
I have used pip to install Fitbit, Pandas, DateTime and also Oauth. To install OAuth I used the following:
pip install oauth -t fitbitAPI
It installed without any issue.
I put the following lines into my Python Script:
import fitbit
import gather_keys_oauth2 as Oauth2
import pandas as pd
import datetime
When I test the script I get the following error message:
Traceback (most recent call last):
File "fitbitAPI.py", line 2, in <module>
import gather_keys_oauth2 as Oauth2
ModuleNotFoundError: No module named 'gather_keys_oauth2'
I spent hours searching the web but have not been able to find anything that's been helpful. Any ideas? Is there another version or way that I need to install OAuth?
Here's how I was able to resolve the error:
Download the fitbit package as described (https://github.com/orcasgit/python-fitbit).
After you install fitbit as described, navigate to the newly created folder \Lib\site-packages\fitbit
Copy and paste the gather_keys_oauth2.py file into the fitbit folder
Then you can from fitbit import gather_keys_oauth2 as Oauth2
One clarification on Jacob Miller's solutions:
Copy and paste the gather_keys_oauth2.py file into the fitbit folder
copy gather_keys_oauth2.py into the Lib/site-packages folder if the above still results in the not found error.
And, I installed cherrypy (required by gather_keys_oauth2.py) using the Anaconda Navigator:
screen shot from Navigator
good luck.
You should be able to source the module from orcasgit. You can download the python script here and stick it in your directory.
I experienced a similar issue and solved by updating my environment and making sure I was using python3. I had activated the wrong environment with the conda activate environmentname command, and so the notebook was throwing this same error.
Install Anaconda-Navigator
Create a new environment with the Anaconda-Navigator tool
Make sure you are using Python 3.x in this new environment
Install cherrpy using the Anaconda-Navigator tool
When you start-up terminal and navigate to the directory of your app, you'll activate your environment with conda activate environmentname and then start up your notebook jupyter notebook. This error should disappear.
Note: there may be some additional packages you need to install. Keep using the anaconda navigator to continue installing the packages; the error messages coming off the notebook will guide you to install the right packages.

"DLL load failed: The specified module could not be found" error on using wordcloud in Jupyter notebook

I installed the word cloud library in python to use wordcloud. I am able to successfully use it in all editors like sublime, etc but when I am trying to use it in Jupyter notebook then it is giving me error:
DLL load failed: The specified module could not be found
I have been trying to solve this issue from last 2 days but not getting success. I would appreciate any kind of help.
I too faced this issue.
the problem was when wordcloud is installed it gets python modules and stores in
**C:\Python27\Lib\site-packages** folder (in my case this is the python executable path this may vary for you) so when you import from jupyter it tries to find it in this path , but wordcloud creates one more folder with same name and downloads all wordcloud module in side this , this is one more level in directory so jupyter is unable to find. so the hack what i did is copied all modules from inner wordclod folder to one level outside i.e
copy all from C:\Python27\Lib\site-packages\wordcloud\wordcloud ->
C:\Python27\Lib\site-packages\wordcloud
so this made the trick and no more error.

I am trying to use scapy on python3 on my macosX; however, I get the following error: OSError: Cannot find libdnet.so

I am trying to use scapy to read a pcap file on my MacOSx using Python 3.
However, when I run the following code:
from scapy.all import rdpcap
I get the following error:
OSError: Cannot find libdnet.so
I looked up how to install libdnet, but I was not able to find out how to install for Python 3. How do you either fix this error or download this package?
You have to upgrade to Scapy's current development version from the official repository.

RiveScript gives an error for python object macros

Is it possible to access the object macros internally in RiveScript? I'm bit confused with that.
I have defined the following script:
> object small python
return "4"
< object
+ small
- <call>small</call>
Which gives me an error when I enter small:
error: [ERR: Object Not Found]
make a space after the object name just like that
- <call>small </call>
The definition of the object seems to be ok, but you are probably running it from https://play.rivescript.com/ or https://www.rivescript.com/try, which only allow JavaScript or CoffeeScript (see the about page).
You can use rivescript-python to run the code, which you can install by:
pip install rivescript
Then put your rivescript in a file (.rive), for example, in helloworld.rive.
Then in python:
from rivescript import RiveScript
bot = RiveScript()
bot.load_directory('.') # set your directory where the .rive file(s) is/are
bot.sort_replies()
Now you can use bot.reply to get the answer for a certain input:
>>> bot.reply('localuser','small')
'4'
Edit: I have tested this code on Ubuntu 14.04 with Python 3.4.3 and Python 2.7.12 and rivescript 1.14.4.

Mako: cannot import the Template class. Have a SyntaxError error in "\mako\template.py", line 622

I want to try Mako with Django instead of Django's default template language. But I'm having a problem when I try to import Mako's Template class as written in the manual:
from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()
I do this in Windows cmd and receive such an error:
C:\Documents and Settings\User>cd C:\py\project\vendor\template\Mako_73 // cd to where I unpacked Mako
C:\py\project\vendor\template\Mako_73>python // run Python interpreter
>>> from mako.template import Template // trying to import and getting an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".\mako\template.py", line 622
exec code in module.__dict__, module.__dict__
^
SyntaxError: invalid syntax
The code from that part:
def _compile_text(template, text, filename):
identifier = template.module_id
source, lexer = _compile(template, text, filename,
generate_magic_comment=template.disable_unicode)
cid = identifier
if not util.py3k and isinstance(cid, unicode):
cid = cid.encode()
module = types.ModuleType(cid)
code = compile(source, cid, 'exec')
exec code in module.__dict__, module.__dict__
return (source, module)
What can it be? I couldn't find anything in Google about this error.
I'm using Python 3.3.
I've downloaded Mako-0.7.3 as tar.gz file and just unzipped it in
C:\py\poject\vendor\template\Mako_73. I do not have this directory in the PYTHONPATH or paths.pth. C:\py\poject is a directory where my Django project lives and in \vendor\template I've decided to put Mako and import it from there.
UPD
I found the solution. I've installed the Pyramid Framework and have taken the Mako from there as the Mako is a default template system in it. And Pyramid's version works fine.
Your basic problem is that you are using Python 3, which is relatively new for large projects like Django.
Secondly, you need to find out how to install packages correctly. I don't know where you got Mako from, but you won't find anywhere that says "just unpack the tarball" - perhaps you are assuming that from your knowledge of PHP, but it's not correct.
On the Mako site, the suggested method of installation is pip.
If you go for downloading manually, you need to read instructions about installing Python packages, for example here: http://wiki.python.org/moin/CheeseShopTutorial
The reason Mako doesn't work for you is that the installation procedure (which you haven't run) converts all the provided Python 2 code so that it works on Python 3. It is not that someone didn't bother to check the code for basic syntax errors!
If you are trying to use Django, though, Python 3 is definitely the wrong choice - the installation instructions clearly say you need to be using Python 2.5 to 2.7: https://docs.djangoproject.com/en/1.4/intro/install/
Since you are new to Python, you should try to walk before you run, and go with the tried and tested path - which is Python 2.7 for Django. Ignoring installation instructions and requirements will only slow you down and make life hard.

Resources