Running script in Python command line - gae-python27

I am quite new to Python. I have python27 installed in my PC(windows). I am trying to run a script in python command line. My script was named "Script". And that contains
import sys # Load a library module
print(sys.platform)
print(2 ** 100) # Raise 2 to a power
x = 'Spam!'
print(x * 8) # String repetition
and when i import the script with writing import Script, it gives this
win32
1267650600228229401496703205376
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py
why the error message appears here? TIA. :)

instead of writing import myscript.py simply use
import myscript
note that myscript.py should be in the same location

Related

Conda with Python3.9 using numpy in Python3.10

I'm trying to install statsmodels in Oracle Machine Learning in Conda enviroment.
My conda version is:
%conda
info
active environment : None
shell level : 0
user config file : /u01/.condarc
populated config files : /usr/share/conda/condarc.d/defaults.yaml
/u01/.condarc
conda version : 4.6.14
conda-build version : not installed
python version : 3.6.8.final.0
base environment : /usr (read only)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /u01/.conda/pkgs
/var/cache/conda/pkgs
envs directories : /u01/.conda/envs
/usr/envs
platform : linux-64
user-agent : conda/4.6.14 requests/2.27.1 CPython/3.6.8 Linux/5.4.17-2136.314.6.3.el7uek.x86_64 oracle/7.9 glibc/2.17
UID:GID : 65000:65000
netrc file : None
offline mode : False
I created the conda enviroment with the next command:
%conda
create -n arima_enviroment python=3.9 xz sqlite libuuid statsmodels numpy
I activated the enviroment with:
%conda
activate arima_enviroment
Test the enviroment with:
%python
import sys
import platform
print("sys.version:", sys.version)
print("sys.version_info:", sys.version_info)
print("platform.python_version:", platform.python_version())
sys.version: 3.9.12 (main, Jun 1 2022, 11:38:51) [GCC 7.5.0]
sys.version_info: sys.version_info(major=3, minor=9, micro=12, releaselevel='final', serial=0)
platform.python_version: 3.9.12
Then I execute the next command for import the ARIMA model.
%python
from statsmodels.tsa.arima_model import arima
But give me the next error:
Fail to execute line 2: from statsmodels.tsa.arima_model import arima
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/usr/local/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/usr/local/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/1675189382222-0/zeppelin_python.py", line 206, in <module>
exec(code, _zcUserQueryNameSpace)
File "<stdin>", line 2, in <module>
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tsa/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tools/tools.py", line 4, in <module>
import numpy as np
File "/usr/local/lib/python3.10/site-packages/numpy/__init__.py", line 144, in <module>
from . import core
File "/usr/local/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/u01/.conda/active_env/bin/python3"
* The NumPy version is: "1.22.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
Why conda is using Numpy in Python 3.10 folder and not the Numpy version installed in Python 3.9? How can repair it?

Unable to import MySQL Connector using PyCharm

import mysql.connector
I was trying to make a database using python. I used the code shown below after the installation of MySQL-connector-python to the python interpreter, but the following output shows in the terminal:
Traceback (most recent call last):
File "F:\coding\sql-course-materials\SQL Course Materials\mysql.py", line 1, in <module>
import mysql.connector
File "F:\coding\sql-course-materials\SQL Course Materials\mysql.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package

Can't build spark py-files with pandas included

I am attempting to package up my dependencies for a spark program I am creating. I have a requirements.txt file as below
pandas
I then run
pip3 install -t dependencies -r requirements.txt
cd dependencies
zip -r ../dependencies.zip .
pyspark --py-files dependencies.zip
And run the line -
import pandas
And I get the error -
Traceback (most recent call last):
File "/mnt/tmp/spark-REDACTED/userFiles-REDACTED/dependencies.zip/pandas/__init__.py", line 31, in <module>
File "/mnt/tmp/spark-REDACTED/userFiles-REDACTED/dependencies.zip/pandas/_libs/__init__.py", line 3, in <module>
File "/mnt/tmp/spark-REDACTED/userFiles-REDACTED/dependencies.zip/pandas/_libs/tslibs/__init__.py", line 3, in <module>
ModuleNotFoundError: No module named 'pandas._libs.tslibs.conversion'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/tmp/spark-REDACTED/userFiles-REDACTED/dependencies.zip/pandas/__init__.py", line 36, in <module>
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
Any ideas on how to fix this?
In order to ship dependency on the worker, there are two ways one is exactly what you did, zip the file, or simple py file then use --py-file. The problem you encountered is because of missing C dependency on the worker side. Pkg like NumPy/pandas all have c dependency.
In order to solve this, create the virtualenv, and zip the virtualenv including
the python executable
PYSPARK_DRIVER_PYTHON = <path to current working python>
PYSPARK_PYTHON = './venv/<path to python executable>'
pyspark --archives = <path to zip file>#venv
or follow this link

Jython ImportError: No module named Apache

I´m trying use Jython for run Apache POI but I have the next problem:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "FRTFormat.py", line 14, in <module>
from org.apache.poi.hssf.usermodel import *
ImportError: No module named apache
I execute Jython using the next script
java.exe -jar C:\dev\lang\jython\2.7.0_old\jython-standalone-2.7.0.jar
And my "Hello World" program is:
import os
import csv
import java.text.SimpleDateFormat as Sdf
from java.io import FileInputStream
from java.io import FileOutputStream
from datetime import datetime
from sys import path
path.append("C:\\dev\\poi-3.14-20160307.jar")
path.append("C:\\dev\\poi-ooxml-3.14-20160307.jar")
from org.apache.poi.hssf.usermodel import *
def ejectFRT(eje):
print ("Hello")
Can Help me someone?
Thanks in advance
Greetings
SOLVED:
The problem was in the script:
java.exe -jar C:\dev\lang\jython\2.7.0_old\jython-standalone-2.7.0.jar
It´s neccesary add:
java.exe -Dpython.cachedir.skip=false -Dpython.cachedir=./tmp -jar jython-standalone-2.7.0.jar

Trouble importing Pandas

I am using the Anaconda distribution on Win7 - when I run python through the powershell I can import pandas and numpy without issue. However, when I run it through sublime (as i do on all my other machines by using a build system that targets the python executable), I get ImportError: No module named builtins
Here is the full detail:
No module named builtins
Traceback (most recent call last):
File "C:\Users\jarjarbinks\Sublime Text Build 3065\test.py", line 3, in <module>
import pandas as pd
File "C:\Users\jarjarbinks\AppData\Local\Continuum\Anaconda\lib\site-packages\pandas\__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "tslib.pyx", line 40, in init pandas.tslib (pandas\tslib.c:63148)
File "C:\Users\jarjarbinks\AppData\Local\Continuum\Anaconda\lib\site-packages\pandas\compat\__init__.py", line 51, in <module>
import builtins
ImportError: No module named builtins
[Finished in 0.3s with exit code 1]
[cmd: ['C:/Users/jarjarbinks/AppData/Local/Continuum/Anaconda/python.exe', 'C:\\Users\\jarjarbinks\\Sublime Text Build 3065\\test.py']]
[dir: C:\Users\jarjarbinks\Sublime Text Build 3065]
[path: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Hyland\Web ActiveX\;C:\Users\jarjarbinks\AppData\Local\Continuum\Anaconda;C:\Users\jarjarbinks\AppData\Local\Continuum\Anaconda\Scripts]
No clue on this one, any help would be greatly appreciated.