EnvironmentError
pinecone.EnvironmentError
Stack trace
Traceback (most recent call last):
File "app.py", line 10, in <module>
pinecone.init(api_key=os.environ['PINECONE_API_KEY'], environment=os.environ['PINECONE_ENVIRONMENT'])
File "/usr/local/lib/python3.9/site-packages/pinecone/__init__.py", line 50, in init
raise EnvironmentError("The environment parameter is deprecated in Pinecone SDK v3. Use Pinecone(api_key=..., environment=...) instead.")
pinecone.EnvironmentError: The environment parameter is deprecated in Pinecone SDK v3. Use Pinecone(api_key=..., environment=...) instead. Why it happens
Pinecone SDK v3 deprecated the global init() function that accepted environment parameters. Instead, it requires creating a Pinecone client instance with environment and API key passed as constructor arguments. Using the old init() method triggers this EnvironmentError.
Detection
Detect this error by monitoring for EnvironmentError exceptions during Pinecone initialization, especially if your code calls pinecone.init() with environment parameters.
Causes & fixes
Using pinecone.init() with environment parameter in SDK v3 which is deprecated
Replace pinecone.init(api_key=..., environment=...) with Pinecone(api_key=..., environment=...) client instantiation.
Not updating code after upgrading Pinecone SDK from v2 to v3
Refactor all Pinecone initialization code to use the new Pinecone class constructor instead of the init() function.
Passing environment variable incorrectly or missing in new client instantiation
Ensure environment is passed as a keyword argument to Pinecone(), e.g. Pinecone(api_key=os.environ['PINECONE_API_KEY'], environment=os.environ['PINECONE_ENVIRONMENT']).
Code: broken vs fixed
import os
import pinecone
# Deprecated usage causing EnvironmentError
pinecone.init(api_key=os.environ['PINECONE_API_KEY'], environment=os.environ['PINECONE_ENVIRONMENT'])
index = pinecone.Index('my-index') # This line triggers error import os
from pinecone import Pinecone
# Fixed usage with Pinecone client instantiation
client = Pinecone(api_key=os.environ['PINECONE_API_KEY'])
index = client.Index('my-index') # Works correctly
print('Pinecone client initialized successfully') Workaround
If immediate refactor is not possible, wrap pinecone.init() call in try/except EnvironmentError and log the error, then delay Pinecone client creation until code can be updated.
Prevention
Always consult Pinecone SDK release notes and migrate to the new client instantiation pattern immediately after upgrading to SDK v3 to avoid deprecated environment usage.